QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276732 | #7894. Many Many Heads | ucup-team956# | WA | 4ms | 3828kb | C++17 | 1006b | 2023-12-06 10:10:37 | 2023-12-06 10:10:37 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int read() {int x; cin >> x; return x;}
void solve() {
string s;
cin >> s;
int n = s.size();
s = " " + s;
vector<int>a(n + 1);
stack<int>stk;
for(int i = 1; i <= n; i++) {
if(s[i] == ')' || s[i] == '(') {
a[i] = 1;
}
else a[i] = 2;
}
int ok = 0;
for(int i = 1; i <= n; i++) {
if(stk.size()) {
int u = stk.top();
if(u == a[i] && ok == 1) {
stk.pop();
}
else {
if(u == a[i]) ok = 1;
stk.push(a[i]);
}
}
else {
stk.push(a[i]);
}
}
if(stk.size() == 0) {
cout << "No\n";
}
else cout << "Yes\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
int t = read();
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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: 3744kb
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: 4ms
memory: 3560kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No Yes No Yes No Yes Yes Yes No Yes No No Yes No Yes Yes Yes No Yes No No Yes No Yes No Yes No Yes No No Yes No No Yes Yes Yes Yes No Yes No No No No Yes No Yes Yes Yes Yes No No Yes No No Yes No Yes No Yes No Yes No No No Yes No No Yes No Yes No No Yes...
result:
wrong answer expected NO, found YES [18th token]