QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#314028#7894. Many Many HeadsWRuperDWA 0ms3732kbC++142.1kb2024-01-25 11:29:082024-01-25 11:29:08

Judging History

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

  • [2024-01-25 11:29:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3732kb
  • [2024-01-25 11:29:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
void solve(){
	string s;
	cin>>s;
	int n = s.length();
	s = " " + s;
	stack <int> stc;
	for(int i = 1; i <= n; i++){
		if(s[i] == ')' or s[i] == '('){
			if(stc.empty())	stc.push(1), s[i] = '(';
			else if(stc.top() == 1)	stc.pop(), s[i] = ')';
			else stc.push(1), s[i] = '(';
		}
		if(s[i] == '[' or s[i] == ']'){
			if(stc.empty())	stc.push(2), s[i] = '[';
			else if(stc.top() == 2)	stc.pop(), s[i] = ']';
			else stc.push(2), s[i] = '[';
		}
	}
	bool fl = 1;
	int mk = 1;
	for(int i = 1; i <= n; i++){
		if(s[i] == '('){
			if(fl)	stc.push(1);
			else{
				puts("No");
				return ;
			}
		}
		if(s[i] == ')'){
			if(stc.top() != 1){
				puts("No");
				return ;
			}
			stc.pop();
			fl = 0;
		}
		if(s[i] == '['){
			if(fl)	stc.push(2);
			else{
				puts("No");
				return ;
			}
		}
		if(s[i] == ']'){
			if(stc.top() != 2){
				puts("No");
				return ;
			}
			stc.pop();
			fl = 0;
		}
		if(stc.empty())	{
			mk = i + 1;
		}
	}
	if(!stc.empty())	{
		puts("No");
		return ;
	}
	fl = 1;
	for(int i = mk + 1; i <= n; i++){
		if(s[i] == '('){
			if(fl)	stc.push(1);
			else{
				puts("No");
				return ;
			}
		}
		if(s[i] == ')'){
			if(stc.top() != 1){
				puts("No");
				return ;
			}
			stc.pop();
			fl = 0;
		}
		if(s[i] == '['){
			if(fl)	stc.push(2);
			else{
				puts("No");
				return ;
			}
		}
		if(s[i] == ']'){
			if(stc.top() != 2){
				puts("No");
				return ;
			}
			stc.pop();
			fl = 0;
		}
		if(stc.empty())	{
			mk = i + 1;
		}
	}
	if(mk <= n){
		puts("No");
	}else{
		puts("Yes");
	}
}

signed main(){
	int t = read();
	while(t--)	solve();
	return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3592kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]