QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#68814#5108. Prehistoric Programschenshi#WA 9ms3984kbC++14676b2022-12-21 08:46:502022-12-21 08:46:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-21 08:46:52]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:3984kb
  • [2022-12-21 08:46:50]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int o=1e6+10;
int n,a[o],b[o],p[o],len,sm;char s[o*10];
inline bool cmp(int A,int B){
	if((a[A]>0)^(a[B]>0)) return a[A]>0;
	if(a[A]>0) return b[A]>b[B];
	return b[A]<b[B];
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;p[i]=i,++i){
		scanf("%s",s+1);len=strlen(s+1);
		for(int j=1;j<=len;b[i]=min(b[i],a[i]),++j)
			if(s[j]=='(') ++a[i];
			else --a[i];
	}
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;++i)
		if(sm+b[p[i]]<0){printf("impossible");return 0;}
		else sm+=a[p[i]];
	if(sm) printf("impossible");
	else for(int i=1;i<=n;++i) printf("%d\n",p[i]); 
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 3984kb

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:

26315
26345
26341
26339
26336
26334
26333
26329
26328
26327
26321
26320
26318
26317
26316
26347
26313
26311
26308
26307
26305
26302
26297
26295
26294
26292
26290
26289
26286
26384
26414
26413
26412
26409
26406
26402
26401
26399
26398
26396
26395
26394
26393
26285
26383
26382
26380
26376
26370
26366
...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 1ms
memory: 3580kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

252
267
573
265
799
859
258
257
929
575
253
268
640
576
933
247
707
245
243
242
934
239
287
915
803
301
863
919
296
481
291
290
570
798
286
801
282
925
280
554
553
271
819
945
820
619
198
943
584
793
854
190
189
188
719
585
725
182
181
947
179
178
177
948
638
715
935
577
496
498
711
857
229
228
502
...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 1ms
memory: 1596kb

input:

2
()
()

output:

1
2

result:

ok good plan

Test #4:

score: 0
Accepted
time: 1ms
memory: 1692kb

input:

2
((
))

output:

1
2

result:

ok good plan

Test #5:

score: 0
Accepted
time: 1ms
memory: 1540kb

input:

2
)(
()

output:

impossible

result:

ok impossible

Test #6:

score: 0
Accepted
time: 1ms
memory: 1600kb

input:

3
()
(
)

output:

2
3
1

result:

ok good plan

Test #7:

score: 0
Accepted
time: 1ms
memory: 1648kb

input:

3
)(
(
)

output:

2
1
3

result:

ok good plan

Test #8:

score: 0
Accepted
time: 1ms
memory: 1660kb

input:

5
))(
(()
)(
(
)

output:

2
4
1
3
5

result:

ok good plan

Test #9:

score: 0
Accepted
time: 1ms
memory: 1692kb

input:

3
((
))())
(

output:

1
3
2

result:

ok good plan

Test #10:

score: 0
Accepted
time: 1ms
memory: 1720kb

input:

6
)
()
()()()
((
)
)

output:

impossible

result:

ok impossible

Test #11:

score: 0
Accepted
time: 1ms
memory: 1728kb

input:

500
(
)
)
(
)(
(
(
)
))(
(
(
(
(
)
)
(
(
)
(
(
)
(
()(()
(
)())
(
(
)
(
)()((
(
)
(
)
)
(
(
(
)
(
(
)
)
)(
(
(
)
)
(
)
(
(
(
)
(
(
())))
(
(
(
)
(
)
)
(
(
)
)
(
(
(
(
(
()
(
(
(
(
(
((
)
(
(
)
(
(
(
)
())
(
(
(
)
(
(
(
)
)
(
)
)
(
)
(
(
(
(
)
(
)
)
)
)
(
)
)))()(
(
)
)
(
)
)(
)
(
)
)
))
(
(
(
(
(
(
...

output:

415
209
208
207
412
205
413
203
414
210
416
199
198
196
194
192
191
420
405
395
232
398
228
227
226
399
404
186
219
406
409
214
410
411
211
153
437
160
159
158
157
156
439
440
436
152
442
149
443
445
143
141
427
184
424
182
180
426
178
177
176
234
428
171
429
431
166
434
435
362
318
315
356
357
311
...

result:

ok good plan

Test #12:

score: -100
Wrong Answer
time: 0ms
memory: 1724kb

input:

50
)
)
((((()())())))(())(())
()(((()))
(((()))(()
()(((
))
)
)()))(()(()())(((((()
(
)
)
)((
)()((
())()))
(())))()
(((
))))(()
()(())(()))())()
)
)
(
(
(
(
((())()())())))(((())
()(
(()(())()((()
()(((()())))())()(
)
)((()
(
)
((
)
()(
(
(
)
)))((())
)
()))()(((()(()
((
((()))(())(()())(()())())()...

output:

impossible

result:

wrong answer you didn't find a solution but jury did