QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138299#6794. Sequence to SequenceQingyuWA 91ms4740kbC++231.3kb2023-08-11 13:05:022023-08-12 03:47:26

Judging History

你现在查看的是最新测评结果

  • [2023-08-12 03:47:26]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:WA
  • 用时:91ms
  • 内存:4740kb
  • [2023-08-11 13:05:04]
  • 评测
  • 测评结果:100
  • 用时:106ms
  • 内存:4728kb
  • [2023-08-11 13:05:02]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3516kb

input:

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

output:

3
3

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 91ms
memory: 4740kb

input:

110121
5
0 0 0 0 0
1 4 5 4 1
5
1 0 0 0 0
0 6 8 6 1
5
2 0 0 0 0
4 4 1 3 6
5
3 0 0 0 0
5 1 1 7 6
5
4 0 0 0 0
6 8 7 0 8
5
5 0 0 0 0
5 9 7 7 5
5
6 0 0 0 0
9 2 2 8 0
5
7 0 0 0 0
9 4 7 0 9
5
8 0 0 0 0
6 7 3 7 5
5
9 0 0 0 0
4 0 9 1 4
5
0 1 0 0 0
0 6 6 3 0
5
1 1 0 0 0
3 4 3 4 9
5
2 1 0 0 0
0 4 0 1 4
5
3 1 0...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 110121 tokens

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 1
time: 0ms
memory: 3492kb

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'