QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#872710 | #7894. Many Many Heads | inksamurai | WA | 1ms | 3712kb | C++23 | 1.7kb | 2025-01-26 03:53:15 | 2025-01-26 03:53:16 |
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);
}
rep(i,n-2){
if(a[i]==a[i+1] and a[i+1]==a[i+2]){
cout<<"Yes\n";
return;
}
}
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: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes Yes Yes No Yes No
result:
wrong answer expected NO, found YES [2nd token]