QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#346580#7894. Many Many HeadsFreeuni1#WA 18ms3884kbC++141.6kb2024-03-08 18:07:522024-03-08 18:07:52

Judging History

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

  • [2024-03-08 18:07:52]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3884kb
  • [2024-03-08 18:07: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;
            q.push(pr[k]);
        }
        if (!ok || sm != n) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

详细

Test #1:

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

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

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: 18ms
memory: 3588kb

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]