QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601415#7894. Many Many HeadsinoaderWA 4ms3604kbC++141.1kb2024-09-29 23:11:372024-09-29 23:11:37

Judging History

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

  • [2024-09-29 23:11:37]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3604kb
  • [2024-09-29 23:11:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
inline int read(){
	int x=0,k=1;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')k=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*k;
}
const int N=1e5+5;
string s;
int x[N];
void sol(){
	cin>>s;
	int a=0,b=0;
	for(char c:s){
		if(c=='('||c==')')++a,b=0;
		else ++b,a=0;
		if(a>2||b>2){
			puts("No");
			return;
		}
	}
	stack<int>t;
	x[0]=0;
	for(int i=0;i<s.length();++i){
		if(i)x[i]=x[i-1];
		char c=s[i];
		if(c=='('||c==')')++x[i];
		else{
			if(t.size()&&(x[i]-x[t.top()])!=1)x[i]=x[t.top()],t.pop();
			else t.push(i);
		}
		if(x[i]>2&&t.empty()){
			puts("No");
			return;
		}
	}
	x[0]=0;
	while(t.size())t.pop();
	for(int i=0;i<s.length();++i){
		if(i)x[i]=x[i-1];
		char c=s[i];
		if(c=='['||c==']')++x[i];
		else{
			if(t.size()&&(x[i]-x[t.top()])!=1)x[i]=x[t.top()],t.pop();
			else t.push(i);
		}
		if(x[i]>2&&t.empty()){
			puts("No");
			return;
		}
	}
	puts("Yes");
}
signed main(){
	int T=read();
	while(T--)sol(); 
}

詳細信息

Test #1:

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

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

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

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]