QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#382808 | #7894. Many Many Heads | He2717970784 | WA | 0ms | 3548kb | C++17 | 1.0kb | 2024-04-08 19:19:05 | 2024-04-08 19:19:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool solve(){
string s;
cin >> s;
vector<int>a;
int n = s.length();
for(int i = 0;i < n;i++){
int x = 0;
if(s[i] == '(' || s[i] == ')'){
x = 1;
}
a.push_back(x);
}
vector<vector<int>>pre(n,vector<int>(2,0));
vector<vector<int>>suf(n,vector<int>(2,0));
for(int i = 0;i < n;i++){
if(i){
pre[i][0] = pre[i - 1][0];
pre[i][1] = pre[i - 1][1];
}
pre[i][a[i]]++;
}
for(int i = n - 1;i >= 0;i--){
if(i < n - 1){
suf[i][0] = suf[i + 1][0];
suf[i][1] = suf[i + 1][1];
}
suf[i][a[i]]++;
}
for(int i = 1;i < n;i++){
if(a[i - 1] != a[i]){
continue;
}
int x = a[i];
if((!(pre[i][!x] & 1)) && (!(suf[i][!x] & 1)) && (pre[i - 1][x] > 1 || suf[i][x] > 1)){
return false;
}
}
return true;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 0;
cin >> t;
while(t--){
bool ans = solve();
if(ans){
cout << "Yes\n";
}
else{
cout << "No\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3496kb
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: 3548kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]