QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480374#7304. Coins 2_LAP_WA 0ms5848kbC++141.5kb2024-07-16 14:57:192024-07-16 14:57:19

Judging History

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

  • [2024-07-16 14:57:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5848kb
  • [2024-07-16 14:57:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 15, maxL = 360360 + 5;

int n;
bool f[2 * N * maxL];
inline void solve() {
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    long long L = 1, A = 0;
    for(int i = 1; i <= n; i ++) A += 1ll * a[i] * i;
    for(int i = 2; i <= n; i ++)
        L = L / __gcd(L, (long long)i) * i;
    f[0] = 1;
    for(int i = 1; i <= n; i ++) if(a[i]) {
        static pair<int, int> que[2 * N * maxL];
        for(int r = 0; r < i; r ++) {
            int hh = 1, tt = 0, cnt = 0;
            que[++tt] = {r, f[r]}, cnt += f[r];
            for(int k = 1; k * i + r <= 2 * n * L; k ++) {
                while(tt - hh + 1 > a[i]) cnt -= que[hh].second, hh ++;
                que[++tt] = {k * i + r, f[k * i + r]}, cnt += f[k * i + r];
                f[k * i + r] = f[k * i + r] || (cnt > 0);
            }
        }
    }
    long long ans = 0;
    // [0, n * L)
    for(int i = 0; i < n * L; i ++) ans += f[i];
    // [n * L, A - n * L]
    long long le = n * L, ri = A - n * L, add = 0;
    for(int i = n * L; i < (n + 1) * L; i ++) add += f[i];
    while(ri >= le && ri % L != L - 1) ans += f[A - ri], ri --;
    if(le <= ri) ans += (ri - le + 1) / L * add;
    // (A - n * L, A]
    for(int i = 0; i < n * L; i ++)
        if(A - i > A - n * L && A - i >= n * L) ans += f[i];
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);

    while(cin >> n) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5848kb

input:

3
0 1 2
3
0 2 3

output:

6
17

result:

wrong answer 2nd numbers differ - expected: '12', found: '17'