QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#872656 | #7894. Many Many Heads | inksamurai | WA | 8ms | 3712kb | C++23 | 1.6kb | 2025-01-26 03:19:27 | 2025-01-26 03:19:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
void slv(){
string s;
cin>>s;
int n=sz(s);
vi a;
rep(i,n){
if(s[i]=='(' or s[i]==')') a.pb(0);
else a.pb(1);
}
vi stk;
rep(i,n){
if(a[i]==0){
if(sz(stk) and a[stk.back()]==0){
s[stk.back()]='(';
s[i]=')';
stk.pop_back();
}else{
stk.pb(i);
}
}else{
if(sz(stk) and a[stk.back()]==1){
s[stk.back()]='[';
s[i]=']';
stk.pop_back();
}else{
stk.pb(i);
}
}
}
auto ask=[&]()->bool{
int x=0,y=0;
map<pii,int> mp;
rep(i,n){
if(s[i]=='('){
if(mp.find({-x,-y})!=mp.end()){
return 1;
}
x+=1;
}else if(s[i]==')'){
x-=1;
mp[{x,y}]=1;
}else if(s[i]=='['){
y+=1;
}else{
y-=1;
}
}
return 0;
};
if(ask()){
cout<<"No\n";
return;
}
rep(i,sz(s)){
if(s[i]=='(') s[i]='[';
else if(s[i]==')') s[i]=']';
else if(s[i]=='[') s[i]='(';
else s[i]=')';
}
if(ask()){
cout<<"No\n";
return;
}
cout<<"Yes\n";
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
int t;
cin>>t;
// t=100;
rep(cs,t){
slv();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
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: 3712kb
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: 8ms
memory: 3584kb
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 Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No Yes No No No No No No Yes No No No No No No No No No No Yes Yes No No No No No No...
result:
wrong answer expected NO, found YES [45th token]