QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382808#7894. Many Many HeadsHe2717970784WA 0ms3548kbC++171.0kb2024-04-08 19:19:052024-04-08 19:19:05

Judging History

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

  • [2024-04-08 19:19:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3548kb
  • [2024-04-08 19:19:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

bool solve(){
	string s;
	cin >> s;
	vector<int>a;
	int n = s.length(); 
	for(int i = 0;i < n;i++){
		int x = 0;
		if(s[i] == '(' || s[i] == ')'){
			x = 1;
		}
		a.push_back(x); 
	}
	vector<vector<int>>pre(n,vector<int>(2,0));
	vector<vector<int>>suf(n,vector<int>(2,0));
	for(int i = 0;i < n;i++){
		if(i){
			pre[i][0] = pre[i - 1][0];
			pre[i][1] = pre[i - 1][1];
		}
		pre[i][a[i]]++;
	}
	for(int i = n - 1;i >= 0;i--){
		if(i < n - 1){
			suf[i][0] = suf[i + 1][0];
			suf[i][1] = suf[i + 1][1];
		}
		suf[i][a[i]]++;
	}
	for(int i = 1;i < n;i++){
		if(a[i - 1] != a[i]){
			continue;
		}
		int x = a[i];
		if((!(pre[i][!x] & 1)) && (!(suf[i][!x] & 1)) && (pre[i - 1][x] > 1 || suf[i][x] > 1)){
			return false;
		}
	}
	return true;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 0;
	cin >> t;
	while(t--){
		bool ans = solve();
		if(ans){
			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: 0ms
memory: 3496kb

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

input:

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

output:

No
No

result:

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