QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#317198 | #7304. Coins 2 | rgnerdplayer# | TL | 0ms | 3800kb | C++20 | 1.1kb | 2024-01-28 17:42:42 | 2024-01-28 17:42:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
auto solve = [&]() {
vector<int> a(n + 1);
i64 tot = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
tot += 1LL * a[i] * i;
}
int L = 1;
for (int i = 1; i <= n; i++) {
L = lcm(L, i);
}
vector<int> dp((n + 1) * L);
dp[0] = 1;
for (int x = 1; x <= n; x++) {
for (int i = (n + 1) * L; i >= 0; i--) {
for (int j = 0; j <= a[x] && i + j * x <= (n + 1) * L; j++) {
dp[i + j * x] |= dp[i];
}
}
}
i64 ans = 0;
for (int i = 0; i < n * L && i <= tot; i++) {
ans += dp[i];
}
for (int i = n * L; i < (n + 1) * L && i <= tot; i++) {
if (dp[i]) {
ans += (tot - n * L) / L + 1;
}
}
cout << ans << '\n';
};
while (cin >> n) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
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