QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626524#7304. Coins 2ucup-team4906#TL 0ms3616kbC++201.1kb2024-10-10 10:00:482024-10-10 10:00:49

Judging History

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

  • [2024-10-10 10:00:49]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3616kb
  • [2024-10-10 10:00:48]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define N 21
int n;
int a[N];
const int M = 1000;
bitset<1001>B;

void sol()
{
    for (int i = 1; i <= n; i ++) cin >> a[i];
    ll sum = 0, t = 0;
    for (int i = 1; i <= n; i ++) 
    {
        sum += a[i] * i;
        if (a[i]) t = gcd(t, i);
    } 
    if (t == 0) {cout << 1 << '\n'; return ;}
    ll ans = sum / t + 1;
    B = 0; B[0] = 1;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= min(a[i], M / i); j ++)B = B | (B << i);
    }
    if (sum <= M)
    {
        for (int i = 1; i <= sum; i ++) if (i % t == 0 && !B[i])ans --;
    }
    else if (sum <= 2 * M)
    {
        for (int i = 1; i <= sum; i ++) if (i % t == 0)
        {
            if (i <= M) {if (!B[i])ans --;}
            else {if (!B[sum - i])ans --;}  
        }
    }
    else
    {
        for (int i = 1; i <= M; i --) if (i % t == 0 && B[i] == 0)ans -= 2;
    }
    cout << ans << '\n';
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int T = 1;
    while (cin >> n) sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: