QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717071 | #7894. Many Many Heads | lihua | WA | 0ms | 3596kb | C++20 | 1.9kb | 2024-11-06 16:47:28 | 2024-11-06 16:47:28 |
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;
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;
else st.pop();
}
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;
else st.pop();
}
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: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes Yes Yes No
result:
wrong answer expected NO, found YES [4th token]