QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#299872 | #7894. Many Many Heads | kiwiHM# | WA | 4ms | 5840kb | C++14 | 851b | 2024-01-07 12:46:03 | 2024-01-07 12:46:04 |
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5792kb
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: 5696kb
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: 5840kb
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]