QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317312#7894. Many Many Headsyz_lyWA 3ms3916kbC++141.3kb2024-01-28 20:21:072024-01-28 20:21:07

Judging History

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

  • [2024-01-28 20:21:07]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3916kb
  • [2024-01-28 20:21:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void work(int k){
	if(k<0){
		putchar('-');
		k=-k;
	}
	if(k>9)
		work(k/10);
	putchar(k%10+'0');
}
/*
先建括号树,然后父亲和儿子的括号种类肯定不同
而且每个点只能有一个儿子,相当于就是一条链,而且最多只能有两条链,并且链顶的括号种类不同
直接判就行了
*/
int t,n,vis[100005];
char s[100005];
stack<int> q;
int main(){
	t=read();
	while(t--){
		scanf("%s",s+1);
		n=strlen(s+1);
		for(int i=1;i<=n;i++){
			if(s[i]=='('||s[i]==')')
				vis[i]=1;
			else
				vis[i]=0;
		}
		while(!q.empty()){
			q.pop();
		}
		int root=0,flag=0,f=0,flag1=0,num=0;
		for(int i=1;i<=n;i++){
			if(q.empty()||vis[q.top()]!=vis[i]){
				if(q.empty()){
					num++;
					if(root&&vis[root]==vis[i]){
						f=1;
						break;
					}
					flag=flag1=0;
				}
				q.emplace(i);
				if(!root)
					root=i;
				if(flag)
					flag1=1;
			}
			else{
				if(flag&&(flag1||vis[flag]==vis[i])){
					f=1;
					break;
				}
				q.pop();
				flag=i;
			}
		}
		if(f)
			puts("No");
		else
			puts("Yes");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

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

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: 3ms
memory: 3916kb

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
No
Yes
Yes
No
Yes
No
Yes
No
No
No
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
...

result:

wrong answer expected NO, found YES [49th token]