QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138299#6794. Sequence to SequenceQingyuWA 106ms4728kbC++231.3kb2023-08-11 13:05:022023-08-11 13:05:04

Judging History

你现在查看的是测评时间为 2023-08-11 13:05:04 的历史记录

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

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3444kb

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: 106ms
memory: 4728kb

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