QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#299841#7894. Many Many HeadskiwiHM#WA 0ms3804kbC++14698b2024-01-07 11:33:132024-01-07 11:33:13

Judging History

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

  • [2024-01-07 11:33:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2024-01-07 11:33:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int T,st[N],top;
char s[N];
int check(char c){
    if(c == '(' || c == ')') return 1;
    return 0;
}
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%s", s + 1);
        int n = strlen(s + 1);
        st[top = 1] = check(s[1]);
        bool flag = 0;
        for(int i = 2; i <= n; i++){
            if(top && check(s[i]) == st[top]) top--;
            else{
                st[++top] = check(s[i]);
            }
            if(top == 0 && i != n){
                flag = 1;
                break;
            }
        }
        if(flag) puts("No");
        else puts("Yes");
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

No
No

result:

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