QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314660 | #7894. Many Many Heads | ucup-team1087 | WA | 4ms | 3928kb | C++14 | 1.8kb | 2024-01-26 02:28:25 | 2024-01-26 02:28:25 |
Judging History
answer
#include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <set>
#include <map>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int N = 1e5 + 1;
char str[N + 1];
bool c[CHAR_MAX], a[N];
void solve() {
scanf("%s", str + 1);
int len = (int)strlen(str + 1);
for (int i = 1; i <= len; ++i) {
a[i] = c[str[i]];
}
vector<bool> stk;
for (int i = 1; i <= len; ++i) {
if (!stk.empty() && stk.back() == a[i]) {
stk.pop_back();
} else {
stk.push_back(a[i]);
}
}
if (!stk.empty()) {
puts("No");
return ;
}
for (int i = 1; i <= len - 2; ++i) {
if (a[i] == a[i + 1] && a[i + 1] == a[i + 2]) {
puts("No");
return ;
}
}
int cnt0 = 0, cnt1 = 0;
for (int i = 1; i <= len - 1; ++i) {
if (a[i] == a[i + 1]) {
if (a[i] == 0 && a[i + 1] == 0) {
if (++cnt0 >= 2) {
puts("No");
return ;
}
} else {
if (++cnt1 >= 2) {
puts("No");
return ;
}
}
++i;
}
}
puts("Yes");
}
int main(int argc, const char * argv[]) {
c['['] = c[']'] = false;
c['('] = c[')'] = true;
int T;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3928kb
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: 0
Accepted
time: 0ms
memory: 3712kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 3704kb
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
Yes Yes Yes Yes Yes Yes No No Yes No No Yes No No No Yes No No Yes Yes No Yes No No Yes No Yes Yes No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [7th token]