QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#299878 | #7894. Many Many Heads | kiwiHM# | WA | 2ms | 7788kb | C++14 | 853b | 2024-01-07 12:47:57 | 2024-01-07 12:47:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n;
int stk[maxn], match[maxn];
char s[maxn];
inline bool solve(int l, int r){
if(l > r) return true;
int cnt[2] = {0, 0};
for(int it = l; it < r; it = match[it] + 1){
if(!solve(it + 1, match[it] - 1)) return false;
++cnt[s[it] == '('];
}
if(cnt[0] >= 2 || cnt[1] >= 2) return false;
return true;
}
inline void solve(){
scanf("%s", s); n = strlen(s);
int top = 0;
for(int i = 0; i < n; ++i){
if(top && (stk[top] & 1) == (s[i] == '[' || s[i] == ']')){
match[i] = (stk[top] >> 1);
match[stk[top] >> 1] = i;
--top;
}
else
stk[++top] = i << 1 | (s[i] == '[' || s[i] == ']');
}
int ans = solve(0, n - 1);
puts(ans ? "Yes" : "No");
}
int main(){
int T;
for(scanf("%d", &T); T--; solve());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5688kb
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: 1ms
memory: 5672kb
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: 2ms
memory: 7788kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes No Yes Yes No Yes No Yes Yes Yes Yes No No No No No No No Yes No No No No Yes No Yes No No No Yes No No No No No No No No No No No No No No Yes Yes No No No No No No No No Yes No No No No Yes No No Yes Yes 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 No No No N...
result:
wrong answer expected YES, found NO [3rd token]