/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 37ms 628.0 KiB
#4 Time Exceeded ≥1066ms ≥19.824 MiB
#5 Time Exceeded ≥1008ms ≥38.746 MiB
#6 Time Exceeded ≥1016ms ≥38.824 MiB
#7 Time Exceeded ≥1030ms ≥54.645 MiB
#8 Time Exceeded ≥1051ms ≥54.238 MiB
#9 Accepted 8ms 1.695 MiB
#10 Time Exceeded ≥1030ms ≥57.02 MiB
#11 Time Exceeded ≥1098ms ≥56.812 MiB
#12 Time Exceeded ≥1086ms ≥56.18 MiB
#13 Time Exceeded ≥1082ms ≥55.723 MiB
#14 Accepted 739ms 5.629 MiB
#15 Time Exceeded ≥1012ms ≥50.418 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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;

map<tuple<ll, ll, ll>, ll> dp;

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

    if (dp.find({i, s, f}) != dp.end())
    {
        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);
        for (auto &a : v)
            cin >> a;

        dp.clear();

        cout << fun(0, 0, 0, v) << endl;
    }

    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:04:29
Judged At
2024-10-03 13:09:03
Judged By
Score
16
Total Time
≥1098ms
Peak Memory
≥57.02 MiB