QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#544117 | #7894. Many Many Heads | New_Folder | WA | 0ms | 3660kb | C++20 | 843b | 2024-09-02 09:45:52 | 2024-09-02 09:45:52 |
Judging History
answer
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
// ( and ) is 1, [ and ] is 0.
string s;
int n;
int flag=0;
int dfs(int x){
int cnt1=0;
for(int i=x+1;i<n;i++){
if((s[i]=='['||s[i]==']')&&cnt1%2==0){
if(cnt1>=4){
flag=1;
}
return i;
}else if((s[i]=='['||s[i]==']')&&cnt1%2==1){
i=dfs(i);
}else{
cnt1++;
}
}
return 0;
}
void solve(){
cin>>s;
n=s.length();
int cnt1=0;
for(int i=0;i<n;i++){
if(s[i]==']'||s[i]=='['){
i=dfs(i);
}else{
cnt1++;
}
}
if(flag||cnt1>=4){
cout<<"No\n";
}else{
cout<<"Yes\n";
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
flag=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]