QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377906#7894. Many Many Headsucup-team2443WA 1ms3844kbC++201.1kb2024-04-05 19:54:412024-04-05 19:54:41

Judging History

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

  • [2024-04-05 19:54:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3844kb
  • [2024-04-05 19:54:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1919810,mod=998244353;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],aa[N];
char s[N];
int ne[N];
int st[N],tt;
bool flag;

void dfs(int l,int r,char ch){
	if(l>=r) return;
	int i=l;
	while(i<=r){
//		cout<<ch<<" "<<s[i]<<endl;
		if(ch==s[i]) flag=1;
		dfs(i+1,ne[i]-1,s[i]);
		i=ne[i]+1;
	}
}
void __(){
	scanf("%s",s+1);
	n=strlen(s+1);
	flag=0;
	tt=-1;
	int c0=0,c1=0;
	int c00=0,c11=0;
	for(int i=1;i<=n;i++){
		if(s[i]==')'||s[i]=='(') c0++;
		else c1++;
	}
	for(int i=1;i<=n;i++){
		if(s[i]==')'||s[i]=='('){
			c00++;
			if(c00<=c0/2) s[i]='(';
			else s[i]=')';
		}
		else{
			c11++;
			if(c11<=c1/2) s[i]='[';
			else s[i]=']';
		} 
		
	}
//	for(int i=1;i<=n;i++) cout<<s[i];
//	cout<<endl;
	for(int i=1;i<=n;i++){
		if(s[i]=='('||s[i]=='['){
			st[++tt]=i;
		}else{
			ne[st[tt]]=i;
			tt--;
		}
	}
	int i=1;
	while(i<=n){
		dfs(i+1,ne[i]-1,s[i]);
		i=ne[i]+1;
	}
	if(flag) puts("No");
	else puts("Yes");
}
signed main(){
	int _;
	cin>>_;
	while(_--){
		__();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3844kb

input:

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

output:

Yes
No
Yes
No
Yes
No

result:

ok 6 token(s): yes count is 3, no count is 3

Test #2:

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

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]