QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626523 | #7304. Coins 2 | ucup-team4906# | RE | 0ms | 3656kb | C++20 | 1.1kb | 2024-10-10 09:59:36 | 2024-10-10 09:59:37 |
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);
}
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: 3656kb
input:
3 0 1 2 3 0 2 3
output:
6 12
result:
ok 2 number(s): "6 12"
Test #2:
score: -100
Runtime Error
input:
1 0 15 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000