QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394843#7894. Many Many Headsucup-team3294#WA 1ms3620kbC++231.1kb2024-04-20 20:25:572024-04-20 20:25:58

Judging History

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

  • [2024-04-20 20:25:58]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2024-04-20 20:25:57]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
#define PII pair<int,int>
#define x first
#define y second
using namespace std;
const int N=1e6+5;
const int mod=1e9+7;
void solve(){
	int n;
	string s;
	cin>>s;
	n=s.size();
	s=" "+s;
	stack<int> st;
	vector<int> c(3),b(3),k(3);
	for(int i=1;i<=n;i++){
		if(s[i]=='('||s[i]==')') b[1]++;
	}
	b[2]=n-b[1];
	b[1]/=2;
	b[2]/=2;
//	cout<<b[1]<<" "<<b[2]<<endl;
	for(int i=n;i>=1;i--){
		int t;
		if(s[i]=='('||s[i]==')') t=1;
		else t=2;
		if(st.size()){
			if(st.top()==t){
				k[t]--;
				st.pop();
			}else if(k[t]){
				c[t]++;
				k[t]++;
				st.push(t);
			}else{
				k[t]++;
				st.push(t);
			}
		}else{
			k[t]++;
			st.push(t);
		}
	}
//	for(int i=1;i<=2;i++){
//		cout<<c[i]<<" ";
//	}
//	cout<<endl;
//	for(int i=1;i<=2;i++){
//		cout<<b[i]<<" ";
//	}
//	cout<<endl;
	if(c[1]==max(b[1]-1,0LL)&&c[2]==max(b[2]-1,0LL)){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

No
No

result:

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