/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 328.0 KiB
#3 Accepted 3ms 516.0 KiB
#4 Accepted 8ms 544.0 KiB
#5 Accepted 9ms 576.0 KiB
#6 Accepted 9ms 564.0 KiB
#7 Accepted 53ms 600.0 KiB
#8 Accepted 55ms 588.0 KiB
#9 Accepted 3ms 540.0 KiB
#10 Accepted 28ms 584.0 KiB
#11 Accepted 3ms 488.0 KiB
#12 Accepted 29ms 584.0 KiB
#13 Accepted 28ms 584.0 KiB
#14 Accepted 5ms 568.0 KiB
#15 Accepted 52ms 592.0 KiB
#16 Accepted 1865ms 616.0 KiB
#17 Time Exceeded ≥2035ms ≥952.0 KiB
#18 Time Exceeded ≥2051ms ≥1.562 MiB
#19 Time Exceeded ≥2082ms ≥1.875 MiB
#20 Accepted 25ms 1.316 MiB
#21 Time Exceeded ≥2047ms ≥956.0 KiB

Code

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

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

    int t;
    cin >> t;

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

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

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

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

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

        int result = 0;
        for (int i = k; i <= totalSum; ++i)
        {
            result = (result + dp[i]);
            if (result > M)
                result -= M;
        }
        int ans = result - 1 + M;
        if (ans > M)
            ans -= M;
        cout << ans << '\n';
    }

}

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:03:39
Judged At
2024-10-03 13:05:26
Judged By
Score
80
Total Time
≥2082ms
Peak Memory
≥1.875 MiB