QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755739 | #7894. Many Many Heads | yumz# | WA | 0ms | 3616kb | C++14 | 896b | 2024-11-16 17:58:27 | 2024-11-16 17:58:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
int a[1000010];
stack<int>q;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while( t-- ){
int ans = 0;
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);
int bj = 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++;
for(int j = f,k = i;j+1 <= k-1; ++j,k--){
if(a[j] == a[j+1])bj = 0;
}
}
}
if( ans >= 3 )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: 3616kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes Yes Yes No Yes Yes
result:
wrong answer expected NO, found YES [2nd token]