QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#311374#7894. Many Many HeadsconfesserWA 4ms3744kbC++171.2kb2024-01-22 11:42:122024-01-22 11:42:12

Judging History

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

  • [2024-01-22 11:42:12]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3744kb
  • [2024-01-22 11:42:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back

const int N=1e5+3;
char s[N];
int st[N];

void slv(){
	cin>>(s+1);
	int n=strlen(s+1);
	int c1=count(s+1,s+n+1,'(')+count(s+1,s+n+1,')'),c2=n-c1;
	if(c1%2||c2%2){
		cout<<"No\n";
		return;
	}
	int tp=0,cnt[2]{};
	F(i,1,n){
		if(s[i]=='('||s[i]==')'){
			if(tp&&st[tp]==1) tp--;
			else st[++tp]=1;
		}else{
			if(tp&&st[tp]==2) tp--;
			else st[++tp]=2;
		}
		if(!tp){
			if(s[i]=='('||s[i]==')') cnt[0]++;
			else cnt[1]++;
		}
	}
	F(i,1,n-3){
		if((s[i]=='('||s[i]==')')&&
		(s[i+1]=='('||s[i+1]==')')&&
		(s[i+2]=='('||s[i+2]==')')&&
		(s[i+3]=='('||s[i+3]==')')){
			cout<<"No\n";
			return;
		}
	}
	if(tp||cnt[0]>=2||cnt[1]>=2){
		cout<<"No\n";
		return;
	}
	cout<<"Yes\n";
}

int main(){
	cin.tie(0)->ios::sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) slv();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

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: 1ms
memory: 3656kb

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: 3744kb

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]