QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682191#7894. Many Many HeadsmvecWA 8ms3836kbC++141.9kb2024-10-27 14:21:102024-10-27 14:21:11

Judging History

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

  • [2024-10-27 14:21:11]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3836kb
  • [2024-10-27 14:21:10]
  • 提交

answer

#include <iostream>
#include <string>
#include <bitset>
#include <stack>
#include <deque>

using namespace std;

struct seq
{
    int l, r, t;
};

string s;
bitset<1000010> bin_s;

bool solve(int l, int r)
{
    if (l >= r)
        return true;
    deque<seq> seqs;
    stack<char> ord;
    int index = 0;
    for (int i = l; i <= r; i++)
    {
        if (bin_s[i])
        {
            if (ord.size() && ord.top() == '[')
                ord.pop();
            else
                ord.push('[');

            if (ord.empty())
            {
                seqs.emplace_back();
                seqs.back().r = i;
                seqs.back().t = 1;
            }
        }
        else
        {
            if (ord.size() && ord.top() == '(')
                ord.pop();
            else
                ord.push('(');

            if (ord.empty())
            {
                seqs.emplace_back();
                seqs.back().r = i;
                seqs.back().t = 0;
            }
        }
    }
    if (seqs.empty())
        return true;
    seqs.front().l = 0;
    auto p1 = seqs.begin(), p2 = p1 + 1;
    while (p2 != seqs.end())
    {
        p2->l = p1->r + 1;
        p1++, p2++;
    }

    int cnts[2] = {0, 0};
    for (auto &p : seqs)
        cnts[p.t]++;

    if (cnts[0] > 1 || cnts[1] > 1)
        return false;

    for (auto &x : seqs)
        if (solve(x.l + 1, x.r - 1))
            return true;

    return true;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> s;
        n = s.size();
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '(' || s[i] == ')')
                bin_s[i] = 0;
            else
                bin_s[i] = 1;
        }

        if (solve(0, n - 1))
            cout << "Yes\n";
        else
            cout << "No\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 8ms
memory: 3836kb

input:

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

output:

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

result:

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