QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665488 | #7894. Many Many Heads | qzez# | WA | 0ms | 3832kb | C++14 | 676b | 2024-10-22 13:29:52 | 2024-10-22 13:29:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T,n,b[N];
char a[N];
int main(){
scanf("%d",&T);
for(;T--;){
scanf("%s",a+1),n=strlen(a+1);
static int top,stk[N];
for(int i=1;i<=n;i++)b[i]=a[i]=='('||a[i]==')';
top=0;
for(int i=1;i<=n;i++){
if(top&&stk[top]==b[i])top--;
else stk[++top]=b[i];
}
if(top){
puts("No");
continue;
}
bool flag=1;
for(int i=1;i<n/2;i++)if(b[i]==b[i+1])flag=0;
for(int i=1;i<=n/2;i++)if(b[i]!=b[n+1-i])flag=0;
puts(flag?"Yes":"No");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
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: 3640kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]