QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#351#138299#6794. Sequence to SequenceQingyuQingyuSuccess!2023-08-12 03:46:362023-08-12 03:46:37

详细

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题目提交者结果用时内存语言文件大小提交时间测评时间
#138299#6794. Sequence to SequenceQingyuWA 91ms4740kbC++231.3kb2023-08-11 13:05:022023-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;
}