QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801833#7894. Many Many Headsjuan_123#WA 0ms3900kbC++141003b2024-12-07 10:06:522024-12-07 10:06:52

Judging History

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

  • [2024-12-07 10:06:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3900kb
  • [2024-12-07 10:06:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,k;
char s[500005];
int op[500005];
void solve(){
	scanf("%s",s+1);n=strlen(s+1);
	int pos1=0,pos2=0;
	for(int i = 1;i<=n;i++){
		if(s[i]=='(' or s[i]==')')op[i]=1;else op[i]=2;
	}
	int cc = 0;
	for(int i = 1;i<n;i++)if(op[i]==op[i+1]){
		if(!pos1)pos1=i;
		else if(!pos2)pos2=i;
		else{
			cout << "No" << endl;return;
		}
	}
	if(!pos2){cout << "Yes" << endl;return;}
		int l1 = pos1,r1 = pos1+1,l2 = pos2,r2 = pos2+1;
		while(l1-1>=1 and r1+1<=n and op[l1-1]==op[r1+1])++r1,--l1;
		while(l2-1>=1 and r2+1<=n and op[l2-1]==op[r2+1])++r2,--l2;
		if(l1==1 and r2==n and r1+1==l2 and op[r1]!=op[l2]){
			cout << "Yes" << endl;return;
		}
	
	cout << "No" << endl;return;
}
signed main(){
	srand(time(0));
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin >> t;
	while(t--)solve();
	return 0;
}/*
3
[]()
[([])][]
[([()])]([()])
 6
 ))
 ((()
 [()]
 ()[()]()
 ([()])
 ([])([])
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3900kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
Yes
Yes
Yes
Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]