QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660938#7894. Many Many Headsfoolnine#WA 0ms3808kbC++201.8kb2024-10-20 13:59:522024-10-20 13:59:52

Judging History

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

  • [2024-10-20 13:59:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3808kb
  • [2024-10-20 13:59:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int check(char c) {
    if (c == '(' || c == ')') {
        return 1;
    } else {
        return -1;
    }
}

void solve() {
    string s;
    cin >> s;

    int ok = 1;

    int n = s.size();

    for (int i = 0; i < n - 2; i++) {
        if (check(s[i]) == check(s[i + 1]) && check(s[i]) == check(s[i + 2])) {
            ok = 0;
        }
    }

    if (!ok) {
        cout << "No\n";
        return;
    }

    vector<pair<int, int>> pre(n + 1);
    for (int i = 0; i < n; i++) {
        int f = check(s[i]);
        if (f == 1) {
            pre[i + 1].first = pre[i].first + 1;
            pre[i + 1].second = pre[i].second;
        } else {
            pre[i + 1].second = pre[i].second + 1;
            pre[i + 1].first = pre[i].first;
        }
    }

    set<pair<int, int>> st1, st2;
    for (int i = 0; i < n - 1; i++) {
        int f1 = check(s[i]), f2 = check(s[i + 1]);
        if (f1 == f2) {
            if (f1 == 1) {
                int t1 = pre[i].first % 2, t2 = pre[i].second % 2;
                if (st1.count(make_pair(t1, t2))) {
                    ok = 0;
                } else {
                    st1.insert(make_pair(t1, t2));
                }
            } else {
                int t1 = pre[i].first % 2, t2 = pre[i].second % 2;
                if (st2.count(make_pair(t1, t2))) {
                    ok = 0;
                } else {
                    st2.insert(make_pair(t1, t2));
                }
            }
        }
    }

    if (!ok) {
        cout << "No\n";
        return;
    }

    cout << "Yes\n";
}

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

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

input:

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

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]