QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#619231#7894. Many Many HeadstsaiWA 0ms4024kbC++14718b2024-10-07 13:34:492024-10-07 13:34:50

Judging History

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

  • [2024-10-07 13:34:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4024kb
  • [2024-10-07 13:34:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 +50;
int trans[N];
int cnt[N];
void solve(){
	stack<int>st;
	string s;
	cin>>s;
  for(int i = 1; i <= s.length(); i++) trans[i] = (s[i-1] == '(' || s[i-1] == ')')? 1 : 2;  
  cnt [0] = cnt[1] = cnt[2] = 0;
  trans[0] = 0;
	for(int i = 0; i <= s.length(); i++){
    if(!st.empty()){
      if(trans[i] == trans[st.top()]){
        st.pop(), cnt[st.top()]++;
        if(cnt[st.top()] >= 2 || cnt[st.top()] >= 2) return printf("No"), void();
      } 
      else st.push(i);
    }
    else st.push(i);
	}
  printf("Yes");
}
int main(){ 
	int t;
	scanf("%d",&t);
	while(t--){
		solve();
    if(t) printf("\n");
	}	
	return 0;
}

详细

Test #1:

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

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

input:

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

output:

No
No

result:

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