QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#872656#7894. Many Many HeadsinksamuraiWA 8ms3712kbC++231.6kb2025-01-26 03:19:272025-01-26 03:19:28

Judging History

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

  • [2025-01-26 03:19:28]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3712kb
  • [2025-01-26 03:19:27]
  • 提交

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

详细

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]