QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626524 | #7304. Coins 2 | ucup-team4906# | TL | 0ms | 3616kb | C++20 | 1.1kb | 2024-10-10 10:00:48 | 2024-10-10 10:00:49 |
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 = 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