QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717169 | #7894. Many Many Heads | lihua | WA | 3ms | 3864kb | C++20 | 2.0kb | 2024-11-06 17:06:34 | 2024-11-06 17:06:39 |
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() >= 3 + cnt) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 3 + cnt && st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && st.top() && st.size() >= 3 + 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() >= 3 + cnt) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 3 + cnt && !st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && !st.top() && st.size() >= 3 + 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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
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: 3620kb
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: 3864kb
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]