QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#665292#7894. Many Many Headszyq_313WA 1ms3568kbC++141.4kb2024-10-22 11:02:152024-10-22 11:02:15

Judging History

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

  • [2024-10-22 11:02:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2024-10-22 11:02:15]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define BUG cout << "HERE IS BUG\n"

const int N = 1e6 + 10;

string s;


void solve(){
	cin >> s;
	string c;	
	vector<char> v;
	
	for (int i = 0; i < s.size(); i ++){
		
		if (v.size() == 0){
			if (s[i] == '(' || s[i] == ')'){
				v.push_back('(');
				c += '(';
			}else{
				v.push_back('[');
				c += '[';
			}
		}else{
			if (v.back() == '('){
				if (s[i] == '(' || s[i] == ')'){
					c += ')';
					v.pop_back();
				}else{
					c += '[';
					v.push_back('[');
				}
			}else if (v.back() == '['){
				if (s[i] == '[' || s[i] == ']'){
					c += ']';
					v.pop_back();
				}else{
					c += '(';
					v.push_back('(');
				}
			}
		}
	}
	
	map<int, int> x, y;//x是() y是[]
	int cnt1 = 0, cnt2 = 0;//cnt1是()的层数 cnt2是[]的层数
	
//	cout << c << endl;
	for (int i = 0; i < c.size(); i ++){
		
		
		if (c[i] == '(') cnt1 ++;
		else if (c[i] == '[') cnt2 ++;
		else if (c[i] == ')'){
			x[cnt1] ++;
			if (x[cnt1] >= 2){
				cout << "No\n";
				return ;
			}
			y[cnt2] = 0;
			cnt1 --;
		}else if (c[i] == ']'){
			y[cnt2] ++;
			if (y[cnt2] >= 2){
				cout << "No\n";
				return ;
			}
			x[cnt1] = 0;
			cnt2 --;
		}
//		cout << i << ' ' << cnt1 << ' ' << cnt2 << ' ' << endl;
	}
	
	cout << "Yes\n";
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	while (t --) solve();
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

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

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]