QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#63826#5108. Prehistoric ProgramsQingyuWA 11ms4280kbC++231006b2022-11-23 14:16:412022-11-23 14:25:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-23 14:25:11]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:4280kb
  • [2022-11-23 14:16:41]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
char s[2000005];
struct node{
	int lim,num,lab;
	bool operator <(const node &a)const{
		if(num>=0&&a.num>=0){
			return lim<a.lim;
		}
		if(num>=0&&a.num<0)return 1;
		if(num<0&&a.num>=0)return 0;
		return num+lim>a.num+a.lim;
	}
}e[2000005];
int main(){
	int n,i,j,vex=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%s",s+1);
		int len=strlen(s+1);
		int now=0,val=0,mis=0;
		for(j=1;j<=len;j++){
			if(s[j]=='('){
				now--;
				val++;
			}
			else{
				now++;
				val--;
				mis=max(mis,now);
			}
		}
		e[i].num=val;
		e[i].lim=mis;
		e[i].lab=i;
		vex=max(mis,vex);
	}
	sort(e+1,e+1+n);
	int now=0;
	for(i=1;i<=n;i++){
		if(now<e[i].lim){
			puts("NO");
			return 0;
		}
		now+=e[i].num;
	}
	if(now==0){
		printf("YES\n");
		for(i=1;i<=n;i++){
			printf("%d ",e[i].lab);
		}
		printf("\n");
	}
	else printf("NO\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 4280kb

input:

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

output:

YES
26700 26740 26738 26737 26729 26727 26724 26723 26716 26715 26714 26713 26711 26709 26703 26744 26698 26696 26695 26693 26692 26689 26685 26682 26679 26677 26674 26672 26671 26670 26779 26819 26817 26815 26813 26810 26809 26806 26803 26802 26800 26792 26787 26784 26783 26668 26778 26777 26776 26...

result:

wrong answer wrong output