QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#872710#7894. Many Many HeadsinksamuraiWA 1ms3712kbC++231.7kb2025-01-26 03:53:152025-01-26 03:53:16

Judging History

你现在查看的是最新测评结果

  • [2025-01-26 03:53:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3712kb
  • [2025-01-26 03:53:15]
  • 提交

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();
	}
}

详细

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]