QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#351 | #138299 | #6794. Sequence to Sequence | Qingyu | Qingyu | Success! | 2023-08-12 03:46:36 | 2023-08-12 03:46:37 |
Details
Extra Test:
Wrong Answer
time: 1ms
memory: 3496kb
input:
10 100 0 53 98 83 16 44 72 43 83 81 0 0 0 89 0 52 100 54 0 0 0 48 0 0 99 0 0 0 0 68 34 53 0 0 63 53 82 98 0 0 48 0 0 0 0 57 52 14 7 64 31 0 81 25 0 69 0 30 23 19 5 22 31 94 72 94 84 6 0 0 0 42 50 38 0 4 49 7 90 49 85 20 36 79 0 22 75 19 52 22 23 0 92 43 85 78 38 0 82 12 82 35 58 93 0 22 16 42 0 0 0 ...
output:
-1 1437 1459 1425 -1 -1 -1 -1 -1 1319
result:
wrong answer 3rd words differ - expected: '1466', found: '1459'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#138299 | #6794. Sequence to Sequence | Qingyu | WA | 91ms | 4740kb | C++23 | 1.3kb | 2023-08-11 13:05:02 | 2023-08-12 03:47:26 |
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int64_t> a(n), b(n);
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 0; i < n; i ++) cin >> b[i];
int64_t x = 0, y = 0, z = 0, w = 0, v = 0, ans = 0;
for(int i = 0; i < n; i ++) {
if(!a[i]) {
if(b[i]) {
ans = -1;
break;
}
}
else {
if(b[i]) {
x = min(x, a[i] - 1);
a[i] += y - x;
if(a[i] < b[i]) {
int64_t t = b[i] - a[i];
if(x < t) {
y += t - x;
auto k = min(v, t - x);
v -= k, ans += t - x - k;
t = x;
}
x -= t;
int64_t s = min(t, v);
y += s, x += s, z += t - s;
}
else {
int64_t t = a[i] - b[i];
if(y < t) {
ans += t - y;
x += t - y;
a[i] -= t - y;
t = y;
}
int64_t aa = a[i] - y - 1;
if(aa < t) y -= t - aa, t = aa;
y -= t;
z += t;
}
z += v;
v = 0;
z = min(z, b[i] - 1 - y);
}
else {
if(a[i] <= x) continue;
ans += a[i] - x;
auto k = min(z, a[i] - x);
x += a[i] - x;
v += k, z -= k;
}
}
}
cout << ans << '\n';
}
return 0;
}