QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#807255 | #4207. Uplifting Excursion | hhoppitree | 0 | 1ms | 5240kb | C++17 | 1.3kb | 2024-12-09 20:34:31 | 2024-12-09 20:34:32 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
long long _a[N << 1], *a = _a + N, _b[N << 1], *b = _b + N, _f[N * N * 2], *f = _f + N * N;
void append(long long v, long long w, long long L) {
if (v > 0) {
for (long long i = L; i >= -L + v; --i) f[i] = max(f[i], f[i - v] + w);
} else {
for (long long i = -L; i <= L + v; ++i) f[i] = max(f[i], f[i - v] + w);
}
}
void apd(long long v, long long w, long long k, long long L) {
if (!v) return;
for (long long i = 1; i <= k; i <<= 1) {
if (k >= i) append(v * i, w * i, L), k -= i;
}
append(v * k, w * k, L);
}
signed main() {
int n; scanf("%d", &n);
long long L; scanf("%lld", &L);
for (int i = -n; i <= n; ++i) scanf("%lld", &a[i]), L -= a[i] * i, b[i] = a[i];
if (L < 0) reverse(a - n, a + n + 1), reverse(b - n, b + n + 1), L = -L;
for (int i = n; i; --i) {
long long t = min(L / i, a[i]);
L -= i * t, b[i] -= t;
}
if (L > n * n) return 0 & puts("impossible");
memset(_f, -0x3f, sizeof(_f));
f[0] = 0;
for (int i = -n; i <= n; ++i) {
apd(i, 1, b[i], n * n), apd(-i, -1, b[i], n * n);
}
if (f[L] < 0) return 0 & puts("impossible");
else printf("%lld\n", accumulate(b - n, b + n + 1, 0ll) + f[L]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5240kb
input:
1 5 0 0 6
output:
impossible
result:
wrong answer 1st lines differ - expected: '5', found: 'impossible'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 0ms
memory: 3804kb
input:
30 38887954194235 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 444113827766 26 511237030935 22 696666627923 315938808146 20 952560827478 924020644151 850666790939 23 587888300072 23 797812801251 911390834853 677171102320 4 2 22 950650764450 278888113729 23 15 15 13 9 637120041802 20 1...
output:
impossible
result:
wrong answer 1st lines differ - expected: '5692035643249', found: 'impossible'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #7:
0%
Subtask #10:
score: 0
Skipped
Dependency #1:
0%