QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627047#7894. Many Many HeadsTytytony#WA 11ms5684kbC++231.1kb2024-10-10 14:35:062024-10-10 14:35:12

Judging History

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

  • [2024-10-10 14:35:12]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:5684kb
  • [2024-10-10 14:35:06]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000010
using namespace std;

char a[N];
int s[N]={0},m[N]={0},cnt;
int persl,perml,Ms,Mm,tf;

void clean(){
	for(int i=0;i<=cnt+2;i++){
		s[i]=0,m[i]=0;
	}
	persl=0,perml=0;
	Ms=0,Mm=0;
	tf=1;
}

int main(){
	int T;
	cin>>T;
	while(T--){
		cin>>a;
		cnt=0;
		for(int i=0;a[i]!=0;i++) cnt++;
		clean();
		for(int i=0;a[i]!=0;i++){
			if(a[i]=='('||a[i]==')'){
				s[persl]++;
				if(s[persl]%2==1||perml==0) perml++;
				else perml--;
				Mm=max(Mm,perml);
			}
			if(a[i]=='['||a[i]==']'){
				m[perml]++;
				if(m[perml]%2==1||persl==0) persl++;
				else persl--;
				Ms=max(Ms,persl);
			}
		}
//		for(int i=0;i<10;i++) cout<<s[i]<<" ";
//		cout<<endl;
//		for(int i=0;i<10;i++) cout<<m[i]<<" ";
//		cout<<endl;
		for(int i=0;i<=Ms&&tf;i++){
			if(s[i]>2){
				tf=0;
				break;
			}
		}
		for(int i=0;i<=Mm&&tf;i++){
			if(m[i]>2){
				tf=0;
				break;
			}
		}
		if(tf) cout<<"Yes\n";
		else cout<<"No\n";
	} 
	return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 11ms
memory: 5676kb

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

result:

wrong answer expected YES, found NO [43rd token]