QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799576#7894. Many Many HeadsTom22lWA 7ms7736kbC++171.5kb2024-12-05 15:57:532024-12-05 15:57:54

Judging History

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

  • [2024-12-05 15:57:54]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:7736kb
  • [2024-12-05 15:57:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
	int x = 0, f = 1;
	char c = getchar();
	while(c != EOF and !isdigit(c))
	{
		if(c == '-')f = -1;
		c = getchar();
	}
	while(isdigit(c))
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
struct node{
	int id;char c;
};
int n;
stack<node>st;
string s;
int fa[1000005];
int cnt1[1000005];
int cnt2[1000005];
signed main()
{
	int T = read();
	while(T --)
	{
		cin>>s;
		while(! st.empty())st.pop();
		for(int i = 0;i < s.size();i ++) cnt1[i]=0,cnt2[i]=0;
		int nf=0,nid=0;
		bool flag=0;
		for(int i = 0;i < s.size();i ++)
		{
			if(st.empty())
			{
				char w;
				if(s[i] == '(' or s[i] == ')'){
					fa[++nid]=nf;
					if(cnt1[nf]){
						flag=1;break;
					}cnt1[nf]++;
					st.push({nid,'('});
				}
				else{
					fa[++nid]=nf;
					if(cnt2[nf]){
						flag=1;break;
					}cnt2[nf]++;
					st.push({nid,'['});
				}nf=nid;
				continue;
			}
			node x = st.top();
			if(s[i] == '(' or s[i] == ')'){
				if(x.c == '('){
					nf=fa[x.id];
					st.pop();
				}else{
					fa[++nid]=nf;
					if(cnt1[nf]){
						flag=1;break;
					}cnt1[nf]++;
					st.push({nid,'('});
				}
			}
			else if(s[i] == '[' or s[i] == ']'){
				if(x.c == '['){
					nf=fa[x.id];
					st.pop();
				}else{
					fa[++nid]=nf;
					if(cnt2[nf]){
						flag=1;break;
					}cnt2[nf]++;
					st.push({nid,'['});
				}
			}
		}
		if(!flag) 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: 7720kb

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

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

input:

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

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
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 [20th token]