QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317195#7304. Coins 2rgnerdplayer#TL 1ms3732kbC++201.2kb2024-01-28 17:41:062024-01-28 17:41:09

Judging History

This is the latest submission verdict.

  • [2024-01-28 17:41:09]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3732kb
  • [2024-01-28 17:41:06]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n;

    auto solve = [&]() {
        vector<int> a(n + 1);
        i64 tot = 0;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            tot += 1LL * a[i] * i;
        }

        int L = 1;
        for (int i = 1; i <= n; i++) {
            L = lcm(L, i);
        }

        vector<int> dp((n + 1) * L);
        dp[0] = 1;

        for (int x = 1; x <= n; x++) {
            vector<int> ndp((n + 1) * L);
            for (int i = 0; i <= L; i++) {
                for (int j = 0; j <= a[x] && i + j * x <= (n + 1) * L; j++) {
                    ndp[i + j * x] |= dp[i];
                }
            }
            swap(dp, ndp);
        }

        i64 ans = 0;
        for (int i = 0; i < n * L && i <= tot; i++) {
            ans += dp[i];
        }
        for (int i = n * L; i < (n + 1) * L && i <= tot; i++) {
            if (dp[i]) {
                ans += (tot - n * L) / L + 1;
            }
        }

        cout << ans << '\n';
    };
    
    while (cin >> n) {
        solve();
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3732kb

input:

3
0 1 2
3
0 2 3

output:

6
12

result:

ok 2 number(s): "6 12"

Test #2:

score: -100
Time Limit Exceeded

input:

1
0
15
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

output:


result: