QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314528 | #7894. Many Many Heads | peter | WA | 0ms | 3656kb | C++14 | 1.2kb | 2024-01-25 19:43:21 | 2024-01-25 19:43:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
stack<int> st;
char ch[maxn];
int pos[maxn];
int main(){
int q;
scanf("%d",&q);
while(q--){
scanf("%s",ch+1);
while(!st.empty()) st.pop();
int n=strlen(ch+1);
for(int i=1;i<=n;i++){
if(ch[i]=='('||ch[i]==')'){
if(!st.empty()&&ch[st.top()]=='('){
int x=st.top();
pos[i]=x;
pos[x]=i;
st.pop();
}else st.push(i);
ch[i]='(';
}else{
if(!st.empty()&&ch[st.top()]=='['){
int x=st.top();
pos[i]=x;
pos[x]=i;
st.pop();
}else st.push(i);
ch[i]='[';
}
}
if(!st.empty()){
puts("No");
continue;
}
// puts("yes");
// printf("%s",ch+1);
pos[0]=-1;
int cnt=0,lst=0,st=1;
bool flag=0;
for(int i=1;i<=n;i++){
if(pos[lst]==lst-1&&cnt&&ch[i]==ch[i-1]){
puts("No");
flag=1;
break;
}
if(pos[lst]==lst-1){
cnt++;
i=pos[st];
lst=pos[i+1];
st=i+1;
}else{
if(ch[i]==ch[i+1]||pos[i]!=lst-1){
puts("No");
flag=1;
break;
}
lst--;
}
}
if(flag) continue;
puts("Yes");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
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: 3648kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]