/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 2ms 528.0 KiB
#4 Accepted 5ms 440.0 KiB
#5 Accepted 5ms 324.0 KiB
#6 Accepted 5ms 568.0 KiB
#7 Accepted 33ms 596.0 KiB
#8 Accepted 32ms 588.0 KiB
#9 Accepted 2ms 532.0 KiB
#10 Accepted 17ms 576.0 KiB
#11 Accepted 2ms 576.0 KiB
#12 Accepted 18ms 580.0 KiB
#13 Accepted 17ms 588.0 KiB
#14 Accepted 3ms 428.0 KiB
#15 Accepted 32ms 592.0 KiB
#16 Accepted 1186ms 616.0 KiB
#17 Time Exceeded ≥2091ms ≥1.066 MiB
#18 Time Exceeded ≥2093ms ≥1.562 MiB
#19 Time Exceeded ≥2092ms ≥2.07 MiB
#20 Accepted 14ms 1.316 MiB
#21 Time Exceeded ≥2088ms ≥964.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll int
const int M = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        vector<ll> v(n);
        ll totalSum = 0;

        for (ll &a : v)
        {
            cin >> a;
            totalSum += a;
        }

        if (totalSum < k)
        {
            cout << "0\n";
            continue;
        }

        vector<ll> dp(totalSum + 1, 0);
        dp[0] = 1;

        for (ll i = 0; i < n; ++i)
        {
            for (ll j = totalSum; j >= v[i]; --j)
            {
                dp[j] = (dp[j] + dp[j - v[i]]) % M;
            }
        }

        ll result = 0;
        for (ll i = k; i <= totalSum; ++i)
        {
            result = (result + dp[i]) % M;
        }

        cout << (result - 1 + M) % M << '\n';
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1094 Number of ways (Hard version)
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 17:26:05
Judged At
2024-10-03 13:04:10
Judged By
Score
80
Total Time
≥2093ms
Peak Memory
≥2.07 MiB