QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#873583#5108. Prehistoric ProgramshhironWA 17ms5280kbC++14978b2025-01-26 17:44:042025-01-26 17:44:05

Judging History

This is the latest submission verdict.

  • [2025-01-26 17:44:05]
  • Judged
  • Verdict: WA
  • Time: 17ms
  • Memory: 5280kb
  • [2025-01-26 17:44:04]
  • Submitted

answer

#include<bits/stdc++.h>
#define INF 0x7fffffff
typedef long long ll;
using namespace std;
const int N=2e6+6;
int n;
struct node{
	int minn,val,id;
	bool operator <(const node &rhs)const{
		return minn<rhs.minn;
	}
};
struct node1{
	int id,val;
	bool operator <(const node1 &rhs)const{
		return val<rhs.val;
	}
};
string s;
priority_queue<node> q;
priority_queue<node1> p;
int ans[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		int len=s.length();
		int num=0,sum=0;
		for(int j=1;j<=len;j++){
			if(s[j-1]=='(') sum++;
			else sum--;
			num=min(num,sum);
		}
		q.push((node){num,sum,i});
	}
	bool lrc=1;
	int nown=0;
	for(int i=1;i<=n;i++){
		while(!q.empty()&&q.top().minn+nown>=0) p.push((node1){q.top().id,q.top().val}),q.pop();
		if(p.empty()){lrc=0;break;}
		nown+=p.top().val;
		if(nown<0){lrc=0;break;}
 		ans[i]=p.top().id;
		p.pop();
	}
	if(!lrc||nown!=0) puts("No");
	else puts("Yes");
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 5280kb

input:

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

output:

Yes

result:

wrong answer wrong output