QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314657#7894. Many Many Headsucup-team1087WA 0ms3628kbC++141.6kb2024-01-26 02:26:002024-01-26 02:26:01

Judging History

你现在查看的是最新测评结果

  • [2024-01-26 02:26:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3628kb
  • [2024-01-26 02:26:00]
  • 提交

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 cnt = 0;
    for (int i = 1; i <= len - 1; ++i) {
        if (a[i] == a[i + 1]) {
            if (++cnt >= 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: 3628kb

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: 3624kb

input:

2
(([([[([
]]))])]])]

output:

No
No

result:

wrong answer expected YES, found NO [1st token]