QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#299844#7894. Many Many HeadskiwiHM#WA 0ms3636kbC++14809b2024-01-07 11:40:022024-01-07 11:40:02

Judging History

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

  • [2024-01-07 11:40:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-01-07 11:40:02]
  • 提交

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);
        if(n == 4 && check(s[1]) != check(s[3])){
            puts("Yes");
            continue;
        }
        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");
    }
}

詳細信息

Test #1:

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

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

input:

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

output:

No
No

result:

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