QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709309 | #7894. Many Many Heads | MIS_T__ | WA | 0ms | 3608kb | C++23 | 1.7kb | 2024-11-04 13:55:38 | 2024-11-04 13:55:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
string s;
cin >> s;
// 1 2 3//
int n = s.size();
int opt = 0;
int cnt = 0;
vector<int>use;
for ( int i = 0 ; i < n ; i++ ) {
if ( s[i] == '(' || s[i] == ')' ) {
if ( opt == 0 ) {
cnt++;
} else {
if ( cnt != 0 ) use.emplace_back(cnt);
opt = 0;
cnt = 1;
}
} else {
if ( opt == 1 ) {
cnt++;
} else {
if ( cnt != 0 ) use.emplace_back(cnt);
opt = 1;
cnt = 1;
}
}
}
if ( cnt ) use.emplace_back(cnt);
// for ( auto i : use ) {
// cout << i << ' ';
// }
// cout << '\n';
for ( auto i : use ) {
if ( i >= 3 ) {
cout << "No\n";
return;
}
}
int num1 = 0, num2 = 0;
for ( int i = 0 ; i < use.size() ; i++ ) {
if ( use[i] == 1 ) {
i += 2;
while ( use[i] != 1 ) {
i += 2;
}
} else {
if ( i%2 == 0 ) num1++;
else num2++;
}
}
for ( int i = 0 ; i < use.size() ; i++ ) {
if ( i+2 < use.size() ) {
if ( use[i] + use[i+1] + use[i+2] == 6 ) {
cout << "No\n";
return;
}
}
}
if ( num1 > 1 || num2 > 1 ) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
int main() {
int T = 1;
cin >> T;
while ( T-- ) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 3608kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]