QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277011#7894. Many Many HeadsSSH#WA 5ms3556kbC++201.1kb2023-12-06 14:32:372023-12-06 14:32:38

Judging History

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

  • [2023-12-06 14:32:38]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3556kb
  • [2023-12-06 14:32:37]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve();
signed main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
	return 0;
}
bool judge(string s) {
	stack<char> st;
	for(int i=0;i < (int)s.size();i++) {
		if(s[i] == '('){
			st.push(s[i]);
		}
		else if(s[i] == ')'){
			if(!(st.size() && st.top() == '(')){
				return false;
			}
			st.pop();
		}
		else if(s[i] == '['){
			st.push(s[i]);
		}
		else{
			if(!(st.size() && st.top() == '[')){
				return false;
			}
			st.pop();
		}
	}
	if(st.size())return false;
	return true;
}
void solve(){
	string s;
	cin >> s;
	int n = s.size();
	if(n > 10){
		cout << "No\n";
		return;
	}
	int ans=0;
	for(int i = 0;i < (1 << n);i++){
		string ss=s;
		for(int j = 0;j < n;j++){
			if((i >> j) & 1){
				if(s[j]=='('||s[j]==')') ss[j]='(';
				else ss[j]='[';
			}
			else {
				if(s[j]=='('||s[j]==')') ss[j]=')';
				else ss[j]=']';
			}
		}
		if(judge(ss)) {ans++;}
	}
	if(ans==1) {
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}

详细

Test #1:

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

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

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

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
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
Yes
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 [82nd token]