QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#677584 | #7894. Many Many Heads | xxk2006 | WA | 0ms | 3948kb | C++23 | 2.4kb | 2024-10-26 13:00:32 | 2024-10-26 13:00:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
char s[100009],t[100009],f[100009];
stack<bool> g;
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf(" %s",s+1);
int n=strlen(s+1),cnt=0;
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')')++cnt;
}
int a=0,b=0;
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')'){
++a;
if((a<<1)<=cnt)t[i]='(';
else t[i]=')';
}
else{
++b;
if((b<<1)<=n-cnt)t[i]='[';
else t[i]=']';
}
}
while(!g.empty())g.pop();
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')'){
if(g.empty()){
g.push(0);
f[i]='(';
continue;
}
if(g.top()==0){
f[i]=')';
g.pop();
}
else{
g.push(0);
f[i]='(';
}
}
else{
if(g.empty()){
g.push(1);
f[i]='[';
continue;
}
if(g.top()==1){
f[i]=']';
g.pop();
}
else{
g.push(1);
f[i]='[';
}
}
}
bool flag=1;
for(int i=1;i<=n;i++){
if(t[i]!=f[i]){
flag=0;
break;
}
}
if(flag)puts("Yes");
else puts("No");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
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: 3948kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]