/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 576.0 KiB
#3 Accepted 10ms 788.0 KiB
#4 Accepted 193ms 53.461 MiB
#5 Accepted 233ms 54.395 MiB
#6 Accepted 231ms 54.391 MiB
#7 Memory Exceeded ≥1110ms ≥128.016 MiB
#8 Memory Exceeded ≥1130ms ≥128.016 MiB
#9 Accepted 3ms 1.07 MiB
#10 Memory Exceeded ≥1118ms ≥128.016 MiB
#11 Memory Exceeded ≥1136ms ≥128.016 MiB
#12 Memory Exceeded ≥1129ms ≥128.016 MiB
#13 Memory Exceeded ≥1131ms ≥128.016 MiB
#14 Accepted 100ms 14.969 MiB
#15 Memory Exceeded ≥1112ms ≥128.016 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll int
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
const int M = 1e9 + 7;
ll n, k;
vector<vector<vector<ll>>> dp;

ll fun(ll i, ll s, ll f, vector<ll> &v)
{
    if (i == n)
    {
        return f and s >= k;
    }

    if (dp[i][s][f] != -1)
    {
        return dp[i][s][f];
    }

    ll ans = 0;
    ans += fun(i + 1, s, 1, v);
    ans %= M;

    ans += fun(i + 1, s + v[i], f, v);
    ans %= M;

    return dp[i][s][f] = ans;
}

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

    int t;
    cin >> t;
    while (t--)
    {
        cin >> n >> k;
        vector<ll> v(n);
        ll maxSum = 0;
        for (auto &a : v)
        {
            cin >> a;
            maxSum += a;
        }
        dp = vector<vector<vector<ll>>>(n + 1, vector<vector<ll>>(maxSum + 1, vector<ll>(2, -1)));

        cout << fun(0, 0, 0, v) << '\n';
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1093 Number of Ways (Easy version)
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 16:07:16
Judged At
2024-10-03 13:08:57
Judged By
Score
31
Total Time
≥1136ms
Peak Memory
≥128.016 MiB