QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277080 | #7894. Many Many Heads | SSH# | WA | 0ms | 3784kb | C++20 | 1.5kb | 2023-12-06 15:12:58 | 2023-12-06 15:12:59 |
Judging History
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";
}
Details
Tip: Click on the bar to expand more detailed information
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]