QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729947#7894. Many Many Headsretired_midlightsWA 12ms4008kbC++141.4kb2024-11-09 18:05:262024-11-09 18:05:27

Judging History

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

  • [2024-11-09 18:05:27]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4008kb
  • [2024-11-09 18:05:26]
  • 提交

answer

#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int st[100010];
int fd(char ch)
{
	if(ch == '#')return 2;
	return (ch=='['||ch==']')?1:0;
}
int main()
{
	int i,j,k,n,m,x,y,z,t;
	scanf("%d",&t);
	while(t--)
	{
		string s;
		cin>>s;
		s='#'+s+'#';
		n=s.size();
		x=0;
		int la=-1;
		int fl=0;
		for(i=0;i<n;i++)
		{
			if(la!=fd(s[i]))
			{
				if(x>0)
				{
					if(st[x-1]>2)
					{
						fl=1;
						break;
					}
					else if(st[x-1]==2)
					{
						x--;
						if(x==0)
						{
							break;
						}
						st[x-1]++;
					}
					else
					{
						st[x]=1;
						x++;
					}
					la=fd(s[i]);
				}
				else
				{
					la=fd(s[i]);
					st[x]=1;
					x++;
				}
			}
			else
			{
				st[x-1]++;
			}
		}
		if(fl)
		{
			printf("No\n");
			continue;
		}
		la=0;
		x=0;
		for(i=1;i<n;i++)
		{
			if(fd(s[i])!=fd(s[i-1]))
			{
				if(x==2)
				{
					la++;
				}if(x>2){
					la=100;
				}
				x=1;
			}
			else
			{
				x++;
			}
		}
		if(la>2)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 12ms
memory: 4008kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No...

result:

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