QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626580 | #7304. Coins 2 | w4p3r | WA | 18ms | 3660kb | C++20 | 1.2kb | 2024-10-10 10:22:10 | 2024-10-10 10:22:11 |
Judging History
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 = 10000;
bitset<M + 1>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 += 1LL * a[i] * i;
if (a[i]) t = gcd(t, i);
}
if (t == 0) {cout << 1 << '\n'; return ;}
ll ans = sum / t + 1;
// cout << "??:" << ans << endl;
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: 3644kb
input:
3 0 1 2 3 0 2 3
output:
6 12
result:
ok 2 number(s): "6 12"
Test #2:
score: 0
Accepted
time: 7ms
memory: 3644kb
input:
1 0 15 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
1 120000000001
result:
ok 2 number(s): "1 120000000001"
Test #3:
score: -100
Wrong Answer
time: 18ms
memory: 3660kb
input:
5 0 2 1 0 0 5 0 0 0 0 53 5 0 6 3 0 0 5 1 0 0 0 1 5 1 0 0 0 0 5 2 0 0 0 116 5 2 0 0 0 0 5 1 0 1 106 1356 5 0 2 0 0 7926 5 0 0 2 1 2004 5 1 0 0 0 1 5 0 0 0 1 5 5 0 0 0 0 0 5 0 1 32840 0 1 5 2 0 0 0 12 5 2 0 0 1 1 5 0 1 79 56770 10 5 1 0 0 1 0 5 0 1 1 2 52165 5 0 0 0 0 1 5 0 0 1 13 0 5 0 0 0 1 10 5 0 0...
output:
6 54 20 4 2 351 3 7207 31635 10027 4 12 1 98524 39 10 227368 4 260837 2 28 22 114 78 76 4 280 233 8 1 12 214572 10 2 1 1 2 108 18199 15926 250077 55576 4 104 282 45419 1687 2973 8 28482 6 4 2988 8 10 102 4 793 69 2 7624 4 237467 84 36589 3 2832 11 25 2 32457 127 33099 2 3 8 116 4 6 260 4 6 29027 4 2...
result:
wrong answer 9th numbers differ - expected: '23781', found: '31635'