QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779051#6134. Soldier Game999#WA 518ms20696kbC++141.5kb2024-11-24 17:14:312024-11-24 17:14:44

Judging History

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

  • [2024-11-24 17:14:44]
  • 评测
  • 测评结果:WA
  • 用时:518ms
  • 内存:20696kb
  • [2024-11-24 17:14:31]
  • 提交

answer

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
typedef long long LL;
using namespace std;
const int N=200007,M=N<<2;
int n,w,A[N],H[N],H2[N],S[M],SM[M],SL[M],SR[M];
struct O {
	int t,i,s;
	bool operator < (const O &_) const {
		return s<_.s;
	}
}W[N];
void up(int u,int m) {
	int l=u<<1,r=u<<1|1;
	SM[u]=SR[l]&&SL[r]||SM[l]&&SM[r]&&H2[m];
	S[u]=S[l]&&S[r]||SL[l]&&SR[r]&&H2[m];
	SL[u]=S[l]&&SL[r]||SL[l]&&SM[r]&&H2[m];
	SR[u]=SR[l]&&S[r]||SM[l]&&SR[r]&&H2[m];
}
void cook(int u=1,int L=1,int R=n) {
	if(L==R) {
		S[u]=SL[u]=SR[u]=SM[u]=0;
		return;
	}
	int m=(L+R)>>1;
	cook(u<<1,L,m),cook(u<<1|1,m+1,R);
}
void upd(int x,int u=1,int L=1,int R=n) {
	if(L==R) {
		S[u]=H[x];
		SL[u]=SR[u]=1,SM[u]=0;
		return;
	}
	int m=(L+R)>>1;
	if(x<=m) upd(x,u<<1,L,m);
	else upd(x,u<<1|1,m+1,R);
	up(u,m);
}
void add(O o,int f=0) {
	int t=o.t,i=o.i;
	if(t==1) {
		H[i]=f;
		upd(i);
	}
	else {
		H2[i]=f;
		upd(i),upd(i+1);
	}
}
void magic() {
	scanf("%d",&n),w=0;
	For(i,1,n) H[i]=H2[i]=0;
	For(i,1,n) scanf("%d",&A[i]);
	For(i,1,n) W[++w]=(O){1,i,A[i]};
	For(i,2,n) W[++w]=(O){2,i-1,A[i]+A[i-1]};
	sort(W+1,W+1+w);
	cook();
	int j=1,ans=INT_MAX;
	For(i,1,w) {
		while(j<=w&&!S[1]) {
			add(W[j++],1);
		}
		if(!S[1]) break;
		ans=min(ans,W[j-1].s-W[i].s);
		add(W[i],0);
	}
	printf("%d\n",ans);
}
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		magic();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 14056kb

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

1
2
0

result:

ok 3 number(s): "1 2 0"

Test #2:

score: -100
Wrong Answer
time: 518ms
memory: 20696kb

input:

10010
1
1000000000
1
-1000000000
2
1000000000 -1000000000
4
1000000000 1000000000 -1000000000 -1000000000
3
100 -100 100
16
-17 91 -19 66 100 -70 -71 76 -58 99 52 19 25 -67 -63 -32
7
-95 -26 63 -55 -19 77 -100
17
-100 72 -53 -32 8 -100 53 44 -100 -65 -81 -59 100 100 57 -47 1
11
99 10 -100 3 32 2 -26...

output:

0
0
0
0
100
135
21
181
189
64
63
164
176
0
147
135
152
36
5
3
38
0
136
0
72
171
146
0
183
77
176
89
0
93
38
109
0
126
158
189
0
0
7
0
188
161
0
116
116
200
0
101
200
39
0
60
139
0
108
107
139
0
178
85993
126
153
168
163
0
53
96
52
126
47
59
79
0
123
188
173
33
0
83
-1295388412
175
188
107
49
53
0
15...

result:

wrong answer 4th numbers differ - expected: '2000000000', found: '0'