QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#248116#6794. Sequence to SequenceatgcWA 90ms6504kbC++141.2kb2023-11-11 17:33:482023-11-11 17:33:48

Judging History

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

  • [2023-11-11 17:33:48]
  • 评测
  • 测评结果:WA
  • 用时:90ms
  • 内存:6504kb
  • [2023-11-11 17:33:48]
  • 提交

answer

/*YYC is Thinking Here*/
#include<bits/stdc++.h>
#define mids(l,r) const auto mid = (l + r) >> 1
#define lb(x) (x&-x)
#define ls (x<<1)
#define rs (ls|1)
#define int long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const int maxn = 1e6+10;
int a[maxn],b[maxn];
int n,x,y,ans;
void sol(){
	cin>>n;
	for(int i = 1;i <= n;++i) cin>>a[i];
	for(int i = 1;i <= n;++i) cin>>b[i];
	ans = x = y = 0;
	//x -1; y +1
	for(int i = 1;i <= n;++i) {
		// deb(i,ans,x,y);
		if(b[i] == 0) {
			if(a[i] - x > 0) {
				ans += a[i] - x;
				x = a[i];
			}
		} else {
			if(a[i] == 0) return cout<<"-1\n",void();
			if(a[i] - x <= 0) x = a[i] - 1;
			if(a[i] - x + y > b[i]) {
				y -= min(y, a[i] - x + y - b[i]);
				int v = a[i] - x + y - b[i];
				x += v, ans += v;
			}
			if(a[i] - x + y < b[i]) {
				x -= min(x, b[i] - (a[i] - x + y));
				int v = b[i] - (a[i] - x + y);
				y += v, ans += v;
			}
		}
		// deb(i,ans,x,y);
	}
	cout<<ans<<'\n';
}
signed main() {
	// freopen("game.in","r",stdin);
	// freopen("game.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int T;cin>>T;while(T--)sol();
}

/*
* I love it all
* Go forward,move forward !
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 90ms
memory: 6504kb

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:

wrong answer 1678th words differ - expected: '12', found: '14'