QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317198#7304. Coins 2rgnerdplayer#TL 0ms3800kbC++201.1kb2024-01-28 17:42:422024-01-28 17:42:42

Judging History

你现在查看的是最新测评结果

  • [2024-01-28 17:42:42]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3800kb
  • [2024-01-28 17:42:42]
  • 提交

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++) {
            for (int i = (n + 1) * L; i >= 0; i--) {
                for (int j = 0; j <= a[x] && i + j * x <= (n + 1) * L; j++) {
                    dp[i + j * x] |= dp[i];
                }
            }
        }

        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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3800kb

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: