QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277080#7894. Many Many HeadsSSH#WA 0ms3784kbC++201.5kb2023-12-06 15:12:582023-12-06 15:12:59

Judging History

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

  • [2023-12-06 15:12:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2023-12-06 15:12:58]
  • 提交

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;
	string s1;
	for (int i = 0; s[i]; i++) {
		if (s[i] == ')' || s[i] == '(') s1 = s1 + '1';
		else s1 = s1 + '0';
	}
	vector<array<int, 2>>pos;
	for (int i = 0; i < s1.size() - 1; i++) {
		if (s1[i] == s1[i + 1]) {
			pos.push_back({i, i + 1});
			i++;
		}
	}
	int l = -1, r = s.size();
	int pre = -1;
	for (auto& [ll, rr] : pos) {
		if (pre == -1) {
			pre = s1[ll] - '0';
		} else {
			if (pre == s1[ll] - '0') {
				cout << "No\n";
				return;
			} else {
				pre = s1[ll] - '0';
			}
		}
		int ok = s1[ll] - '0';
		ll--;
		rr++;	
		ok ^= 1;
		while (ll > l && rr < r) {
			if (s1[ll] == s1[rr] && ok == s1[ll] - '0') {
				ll--, rr++;
			} else {
				cout << "No\n";
				return;
			}
			ok ^= 1;
		}
		l = rr + 1;
		pre=ok^1;
	}
	cout << "Yes\n";
}

詳細信息

Test #1:

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

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

input:

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

output:

Yes
Yes

result:

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