QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#779062#6134. Soldier Game999#WA 505ms20192kbC++141.5kb2024-11-24 17:17:412024-11-24 17:17:42

Judging History

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

  • [2024-11-24 17:17:42]
  • 评测
  • 测评结果:WA
  • 用时:505ms
  • 内存:20192kb
  • [2024-11-24 17:17:41]
  • 提交

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) {
	S[u]=SL[u]=SR[u]=SM[u]=0;
	if(L==R) 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();
	}
}

详细

Test #1:

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

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: 505ms
memory: 20192kb

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
-1294967296
100
135
103
181
189
84
63
164
176
0
147
135
152
36
200
131
134
0
136
0
72
171
146
0
183
77
176
89
200
135
38
109
119
126
158
189
70
0
38
999804364
188
161
0
116
116
200
0
101
200
39
0
183
139
0
183
107
139
0
178
85993
126
153
168
163
96
53
96
52
126
47
130
79
0
123
188
173
33
0
83
...

result:

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