QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717106 | #7894. Many Many Heads | lihua | WA | 3ms | 3624kb | C++20 | 2.0kb | 2024-11-06 16:56:00 | 2024-11-06 16:56:00 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define int long long
const int N = 2e6 + 10;
const int INF = 0x3f3f3f3f3f3f3f3fLL;
typedef __int128 ll;
int a[N];
string s;
void solve() {
int k = 0;
cin >> s;
for (register int i = 0; i < s.size(); ++i) {
if (s[i] == '(' || s[i] == ')') a[++k] = 1;
else a[++k] = 0;
}
stack<int> st;
int cnt = 0, tmp = 0;
for (register int i = 1; i <= k; ++i) {
if (st.empty()) {
st.push(a[i]);
}
else {
if (st.top() == 0) {
if (a[i] == 1) cnt += st.size() - 1, ++tmp;
else {
cnt = !(tmp & 1) ? 0 : cnt;
st.pop(), tmp = 0;
}
}
else {
if (st.size() >= 4 + cnt) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 4 + cnt && st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && st.top() && st.size() >= 4 + cnt) {
cout << "No" << "\n";
return;
}
while (!st.empty()) {
st.pop();
}
cnt = 0;
for (register int i = 1; i <= k; ++i) {
if (st.empty()) {
st.push(a[i]);
}
else {
if (st.top() == 1) {
if (a[i] == 0) cnt += st.size() - 1, ++tmp;
else {
cnt = !(tmp & 1) ? 0 : cnt;
st.pop(), tmp = 0;
}
}
else {
if (st.size() >= 4 + cnt) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 4 + cnt && !st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && !st.top() && st.size() >= 4 + cnt) {
cout << "No" << "\n";
return;
}
cout << "Yes" << "\n";
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 3624kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No Yes Yes No No No No No Yes No Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No Yes No No No No No Yes Yes No No No No No No No No No Yes No Yes No Yes No No No...
result:
wrong answer expected NO, found YES [37th token]