QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660938 | #7894. Many Many Heads | foolnine# | WA | 0ms | 3808kb | C++20 | 1.8kb | 2024-10-20 13:59:52 | 2024-10-20 13:59:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int check(char c) {
if (c == '(' || c == ')') {
return 1;
} else {
return -1;
}
}
void solve() {
string s;
cin >> s;
int ok = 1;
int n = s.size();
for (int i = 0; i < n - 2; i++) {
if (check(s[i]) == check(s[i + 1]) && check(s[i]) == check(s[i + 2])) {
ok = 0;
}
}
if (!ok) {
cout << "No\n";
return;
}
vector<pair<int, int>> pre(n + 1);
for (int i = 0; i < n; i++) {
int f = check(s[i]);
if (f == 1) {
pre[i + 1].first = pre[i].first + 1;
pre[i + 1].second = pre[i].second;
} else {
pre[i + 1].second = pre[i].second + 1;
pre[i + 1].first = pre[i].first;
}
}
set<pair<int, int>> st1, st2;
for (int i = 0; i < n - 1; i++) {
int f1 = check(s[i]), f2 = check(s[i + 1]);
if (f1 == f2) {
if (f1 == 1) {
int t1 = pre[i].first % 2, t2 = pre[i].second % 2;
if (st1.count(make_pair(t1, t2))) {
ok = 0;
} else {
st1.insert(make_pair(t1, t2));
}
} else {
int t1 = pre[i].first % 2, t2 = pre[i].second % 2;
if (st2.count(make_pair(t1, t2))) {
ok = 0;
} else {
st2.insert(make_pair(t1, t2));
}
}
}
}
if (!ok) {
cout << "No\n";
return;
}
cout << "Yes\n";
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 3472kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]