QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543132#7894. Many Many HeadsNew_Folder#WA 0ms3660kbC++14936b2024-09-01 14:13:122024-09-01 14:13:13

Judging History

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

  • [2024-09-01 14:13:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-09-01 14:13:12]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define int long long
//#define pi 3.1415926
typedef long long ll;
using namespace std;
int mod=998244353;

int fp(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans*=a,ans%=mod;
		a*=a,a%=mod;
		b>>=1;
	}
	return ans;
}

void solve(){
	string str;
	cin>>str;bool ans=1;
	int len=str.length();
	int cnt1=0,cnt2=0;
	for(int i=0;i<=len-1;i++){
		if(str[i]=='('||str[i]==')') cnt1++;
		else cnt2++;
	}
	cnt1/=2,cnt2/=2;
	bool flag=1;
	if(str[0]=='('||str[0]==')') flag=0,cnt1--;
	else cnt2--;
	for(int i=1;i<=len-1;i++){
		if(str[i]=='('||str[i]==')'){
			if(!flag&&cnt1>0) ans=0;
			else flag=0,cnt1--;
		}
		else{
			if(flag&&cnt2>0) ans=0;
			else flag=1,cnt2--;
		}
	}
	if(ans) cout<<"Yes\n";
	else cout<<"No\n";
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int t;cin>>t;while(t--) 
	solve();
	return 0;
}	

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

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: 3560kb

input:

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

output:

No
No

result:

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