QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314316 | #7894. Many Many Heads | wdw | WA | 4ms | 3572kb | C++14 | 2.6kb | 2024-01-25 15:32:32 | 2024-01-25 15:32:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N=1205+5;
const double eps=1e-10;
const int mod=1e9;
#define endl '\n'
void solve() {
string s;
cin>>s;
int f=0;
int f2=0;
for(int i=0;i<s.size();i++){
if(s[i]==')'||s[i]=='('){
f2=0;
f++;
if(f==3){
cout<<"No"<<endl;
return;
}
}else if(s[i]=='['||s[i]==']'){
f=0;
f2++;
if(f2==3){
cout<<"No"<<endl;
return;
}
}
}
/* stack<int>q;
for(int i=0;i<s.size();i++){
if(!q.empty()){
if(q.top()==1){
if(s[i]==')'||s[i]=='('){
q.pop();
}else{
q.push(0);
}
}else{
if(s[i]==')'||s[i]=='('){
q.push(1);
}else{
q.pop();
}
}
}
}
if(!q.empty()){
cout<<"No"<<endl;
return;
}*/
stack<int>q1;
vector<int>a(s.size()+5);
int x=1;
int f1=0;
for(int i=0;i<s.size();i++){
if(s[i]=='('||s[i]==')'){
a[x]++;
if(a[x]==3){
cout<<"No"<<endl;
return;
}
if(!q1.empty()&&q1.top()==1){
q1.pop();
}else{
q1.push(1);
}
}else{
if(!q1.empty()&&q1.top()==0){
q1.pop();
x--;
}else{
x++;
q1.push(0);
}
}
}
int f3=0;
int x2=1;
vector<int>a2(s.size()+5);
stack<int>q;
for(int i=0;i<s.size();i++){
if(s[i]=='['||s[i]==']'){
a2[x2]++;
if(a2[x2]==3){
cout<<"No"<<endl;
return;
}
if(!q.empty()&&q.top()==0){
q.pop();
}else{
q.push(0);
}
}else{
if(!q.empty()&&q.top()==1){
q.pop();
x2--;
}else{
x2++;
q.push(1);
}
}
}
cout<<"Yes"<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
// cout<<fixed<<setprecision(2);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 3572kb
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: 3524kb
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 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 ...
result:
wrong answer expected YES, found NO [43rd token]