QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276804 | #7894. Many Many Heads | Redcrown# | WA | 4ms | 5720kb | C++17 | 1.5kb | 2023-12-06 10:57:17 | 2023-12-06 10:57:18 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ssz(x) ((int)x.size())
using namespace std;
const int N=1e6+5;
int n,m;
inline int red(){
int data=0;bool w=0;char ch=getchar();
while(ch!='-' && (ch<'0' || ch>'9'))ch=getchar();
if(ch=='-') w=1,ch=getchar();
while(ch>='0' && ch<='9') data=(data<<3)+(data<<1)+ch-'0',ch=getchar();
return w?-data:data;
}
int sta[N];
char s[N];
void solve(){
scanf("%s",s+1);
n=strlen(s+1);
for(int i=1;i<=n;i++){
sta[i]=0;
}
bool flag1=1,flag2=1;
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')'){
if(flag1)sta[i]=1,flag1=0;
else{
if(sta[i-1]==1&&(s[i-1]=='['||s[i-1]==']')){
sta[i]=1;
}
}
}
if(s[i]=='['||s[i]==']'){
if(flag2)sta[i]=1,flag2=0;
else{
if(sta[i-1]==1&&(s[i-1]=='('||s[i-1]==')')){
sta[i]=1;
}
}
}
}
flag1=1,flag2=1;
for(int i=n;i>=1;i--){
if(sta[i])continue;
if(s[i]=='('||s[i]==')'){
if(flag1)sta[i]=2,flag1=0;
else{
if(sta[i+1]==2&&(s[i+1]=='['||s[i+1]==']')){
sta[i]=2;
}
}
}
if(s[i]=='['||s[i]==']'){
if(flag2)sta[i]=2,flag2=0;
else{
if(sta[i+1]==2&&(s[i+1]=='('||s[i+1]==')')){
sta[i]=2;
}
}
}
}
int res1=0,res2=0;
for(int i=1;i<=n;i++){
if(s[i]=='('||s[i]==')')res1+=(sta[i]==0);
if(s[i]=='['||s[i]==']')res2+=(sta[i]==0);
}
if(res1>1||res2>1)puts("No");
else puts("Yes");
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
int T=red();
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
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: 0
Accepted
time: 1ms
memory: 5720kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 3768kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No No No No No No Yes Yes No No Yes No No No No Yes No No No No No No No No No Yes Yes No No No No No No No No No No No No Yes Yes No No No No No No No No No Yes No No No No No No No No No No Yes No No No No No No No No No No...
result:
wrong answer expected YES, found NO [22nd token]