QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346589#7894. Many Many HeadsFreeuni1#WA 13ms3880kbC++141.6kb2024-03-08 18:14:522024-03-08 18:14:53

Judging History

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

  • [2024-03-08 18:14:53]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3880kb
  • [2024-03-08 18:14:52]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
main() {
    ios::sync_with_stdio(0);
    int t;
    cin >> t;
    while (t --) {
        string x;
        cin >> x;
        int n = x.size();
        vector<int> w(n + 5),v(n + 5), pr(n + 5), nx(n + 5), fx(n + 5);
        queue<int> q;
        int ii = 1;
        v[ii] = 1;
        w[0] = (x[0] == '(' || x[0] == ')');
        for (int i = 1; i < x.size(); i ++) {
            w[i] = (x[i] == '(' || x[i] == ')');
            if (w[i] == w[i-1]) v[ii] ++;
            else {
                if (v[ii] >= 2) {q.push(ii);}
                pr[ii] = ii - 1;
                nx[ii] = ii + 1;
                ii ++;
                v[ii] = 1;
            }
        }
        pr[ii] = ii-1;
        nx[ii] = ii + 1;
        //cout << v[ii] << "!!";
        if (v[ii] >= 2)q.push(ii);
        int sm = 0, ok = 1;
        while (q.size()) {
            int k = q.front();
            //cout << k << " " << v[k] << endl;
            q.pop();
            if (fx[k]) continue;
            if (v[k] != 2) {
                ok = 0;
                break;
            }
            sm += 2;
            if (pr[k] == 0 || nx[k] > ii) {
                continue;
            }
            v[pr[k]] += v[nx[k]];
            nx[pr[k]] = nx[nx[k]];
            pr[nx[nx[k]]] = pr[pr[k]];
            fx[nx[k]] = 1;
            //cout <<"^^"<< k << " " << pr[k] << endl;
            if (v[pr[k]] >= 2)q.push(pr[k]);
        }
        if (!ok || sm != n) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 13ms
memory: 3540kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
Yes
No
Yes
No
No
Yes
No
Yes
No
No
No
No
No
No
Yes
No
No
Yes
Yes
No
No
No
Yes
No
Yes
Yes
No
Yes
No
No
No
Yes
Yes
No
No
Yes
No
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
Yes
No
No
...

result:

wrong answer expected NO, found YES [18th token]