QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755166 | #7894. Many Many Heads | yumz# | WA | 0ms | 3560kb | C++23 | 1.5kb | 2024-11-16 16:36:04 | 2024-11-16 16:36:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int a[1000010];
vector<pair<int,int>>ans;
stack<int>q;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while( t-- ){
ans.clear();
while( !q.empty() )q.pop();
string s;
cin >> s;
int n = s.length();
s = " "+s;
for(int i = 1;i <= n; ++i){
if( s[i] == '(' || s[i] == ')' )a[i] = 0;
else a[i] = 1;
}
q.push(1);
for(int i = 2;i <= n; ++i){
int f = 0 ;
if( !q.empty() )f = q.top(),q.pop();
if( f == 0 ){
q.push(i);
continue;
}
if( a[f] != a[i] )q.push(f),q.push(i);
else if( q.size() == 0 )ans.push_back({f,i});
}
int bj = 1;
for(int i = 0;i < ans.size(); ++i){
for(int j = ans[i].first,k = ans[i].second;j+1 <= k-1; ++j,k--){
if(a[j] == a[j+1])bj = 0;
}
// for(int j = ans[i].first;j <= ans[i].second; ++j){
// cout << a[j] ;
// }
// cout << endl;
}
for(int i = 0;i < ans.size()-1; ++i){
int x = ans[i].second,y = ans[i+1].first;
if( a[x] == a[y] )bj = 0;
}
if( bj )cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3560kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes Yes Yes No
result:
wrong answer expected NO, found YES [4th token]