QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#311381 | #7894. Many Many Heads | confesser | WA | 7ms | 3696kb | C++17 | 1.3kb | 2024-01-22 11:49:41 | 2024-01-22 11:49:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
const int N=1e5+3;
char s[N];
int st[N];
void slv(){
cin>>(s+1);
int n=strlen(s+1);
int tp=0;
F(i,1,n){
if(s[i]=='('||s[i]==')'){
if(tp&&st[tp]==1) tp--;
else st[++tp]=1;
}else{
if(tp&&st[tp]==2) tp--;
else st[++tp]=2;
}
}
if(tp){
cout<<"No\n";
return;
}
F(i,1,n-3){
if((s[i]=='('||s[i]==')')&&
(s[i+1]=='('||s[i+1]==')')&&
(s[i+2]=='('||s[i+2]==')')){
cout<<"No\n";
return;
}
if((s[i]=='['||s[i]==']')&&
(s[i+1]=='['||s[i+1]==']')&&
(s[i+2]=='['||s[i+2]==']')){
cout<<"No\n";
return;
}
}
int cnt=0;
F(i,1,n-1){
if((s[i]=='('||s[i]==')')&&(s[i+1]=='('||s[i+1]==')')){
cnt++;
i++;
continue;
}
if((s[i]=='['||s[i]==']')&&(s[i+1]=='['||s[i+1]==']')){
cnt++;
i++;
continue;
}
}
if(cnt<=2) cout<<"Yes\n";
else cout<<"No\n";
}
int main(){
cin.tie(0)->ios::sync_with_stdio(0);
int t;
cin>>t;
while(t--) slv();
}
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: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: 0
Accepted
time: 2ms
memory: 3640kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No Yes No No No No No No Yes No No Yes Yes No No No Yes No No No No Yes No No No Yes Yes No No Yes 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...
result:
ok 15134 token(s): yes count is 132, no count is 15002
Test #4:
score: -100
Wrong Answer
time: 7ms
memory: 3620kb
input:
100000 ][[][[ ())))( )()))) ]]][[[ )[]))( ()[[)( )()))) [[[][] [][][] ))[]]] ]]]][[ ][]]][ (][))) ((([]( ][[]]] )([)([ ))()(( [)[[)[ ((())) )(][[] ][[[[[ ()(((( ][][]] ][)()( ]]]]][ (()(() )([((] [][[]] ]][]][ )((()) ][[[[[ [)[[([ (([[)( (((()) )((()( ))()() ()(((( [[][][ ))[])( (((()( ]]][[] ()[[]]...
output:
No No No No Yes No No No No No No No Yes No No Yes No Yes No No No No No No No No Yes No No No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No Yes Yes No No No Yes No No Yes No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No Yes No No...
result:
wrong answer expected NO, found YES [5th token]