QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#299844 | #7894. Many Many Heads | kiwiHM# | WA | 0ms | 3636kb | C++14 | 809b | 2024-01-07 11:40:02 | 2024-01-07 11:40:02 |
Judging History
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]