QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619285#7894. Many Many HeadstsaiWA 8ms4008kbC++14920b2024-10-07 13:45:112024-10-07 13:45:12

Judging History

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

  • [2024-10-07 13:45:12]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:4008kb
  • [2024-10-07 13:45:11]
  • 提交

answer

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3712kb

input:

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

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Wrong Answer
time: 8ms
memory: 3724kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

wrong answer expected YES, found NO [20th token]