QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717010 | #7894. Many Many Heads | lihua | WA | 3ms | 3840kb | C++20 | 1.8kb | 2024-11-06 16:37:39 | 2024-11-06 16:37:40 |
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;
for (register int i = 1; i <= k; ++i) {
if (st.empty()) {
st.push(a[i]);
}
else {
if (st.top() == 0) {
if (a[i] == 1) continue;
else st.pop();
}
else {
if (st.size() >= 4) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 4 && st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && st.top() && st.size() >= 4) {
cout << "No" << "\n";
return;
}
while (!st.empty()) {
st.pop();
}
for (register int i = 1; i <= k; ++i) {
if (st.empty()) {
st.push(a[i]);
}
else {
if (st.top() == 1) {
if (a[i] == 0) continue;
else st.pop();
}
else {
if (st.size() >= 4) {
cout << "No" << "\n";
return;
}
st.push(a[i]);
if (st.size() >= 4 && !st.top()) {
cout << "No" << "\n";
return;
}
}
}
}
if (!st.empty() && !st.top() && st.size() >= 4) {
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: 3812kb
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: 3840kb
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: 3560kb
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 No No No No No No No Yes No Yes No No No No No Yes No No No No Yes No No No No No Yes No Yes No No No No No No No No No No No No No No No No No No Yes No No No No No No No No ...
result:
wrong answer expected YES, found NO [36th token]