QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249991#6794. Sequence to SequenceatgcAC ✓12ms5488kbC++142.6kb2023-11-12 19:18:002023-11-12 19:18:01

Judging History

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

  • [2023-11-12 19:18:01]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:5488kb
  • [2023-11-12 19:18:00]
  • 提交

answer

/*YYC is Thinking Here*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 10;

#define Fs 100000
#define inline __inline__ __attribute__((always_inline))
#define iopt inline IO& operator
#define Tc()(_A==_B&&(_B=(_A=Fi)+fread(Fi,1,100000,stdin),_A==_B)?EOF:*_A++)
#define Pc(Ch)(FS<Fs?Fo[FS++]=Ch:(fwrite(Fo,1,Fs,stdout),Fo[(FS=0)++]=Ch))
int Tp,FS;char *_A,*_B,Fi[Fs],Fo[Fs],Sk[Fs];
struct IO{template<typename T>iopt>>(T&x){x=0;char Ch,F=0;while(!isdigit(Ch=Tc()))if(is_signed<T>::value&&Ch=='-')F=1;while(x=10*x +(Ch&15),isdigit(Ch=Tc()));if(is_signed<T>::value&&F)x=-x;return*this;}iopt>>(char*x){int I=0;for(;((x[I]=Tc())!=' ')&&(x[I]!='\n');++I);x[I]='\0';return*this;}iopt>>(char&x){x=Tc();return*this;}template<typename T>iopt<<(T x){if(!x){return Pc('0'),*this;}if(x<0)Pc('-'),x=-x;while(x)Sk[++Tp]=x%10+48,x/=10;while(Tp)Pc(Sk[Tp--]);return*this;}iopt<<(const char*x){for(;*x!='\0';Pc(*(x++)));return*this;}iopt<<(char x){Pc(x);return*this;};~IO(){fwrite(Fo,1,FS,stdout),FS=0;}void tie(int){}}cio;
#define cin cio
#define cout cio

int n, x, y, z, ans, a[maxn], b[maxn];
void solve() {
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	for(int i = 1; i <= n; ++i) cin >> b[i];
	x = y = z = ans = 0;
	for(int i = 1; i <= n; ++i) {
		int a = ::a[i], b = ::b[i];
		if(b == 0) {
			if(x < a) {
				int d = a - x;
				if(d <= z) x += d, y += d, z -= d, ans += d;
				else x += d, y += z, z = 0, ans += d;
			}
		} else {
			if(a == 0) return cout << "-1\n", void();
			x = min(x, a - 1);
			y = min(y, b - 1);
			if(a - x + y < b) { //should +
				int xmv = min(x, b - (a - x + y));
				x -= xmv, z += xmv;
				int v = b - a + x - y;
				y += v, ans += v;
			} else {
				int ymv = min(y, a - x + y - b);
				y -= ymv, z += ymv;
				int v = a - x + y - b;
				x += v, ans += v;
			}
			z = min(z, a - x - 1);
		}
	}
	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--)solve();
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 12ms
memory: 5488kb

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: 0
Extra Test Passed