QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682120#7894. Many Many HeadsmvecWA 0ms3816kbC++141.7kb2024-10-27 14:01:232024-10-27 14:01:24

Judging History

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

  • [2024-10-27 14:01:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-10-27 14:01:23]
  • 提交

answer

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

using namespace std;

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

bitset<1000010> bin_s;
seq seqs[500010];

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

        stack<char> ord;
        int index = 0;
        for (int i = 0; i < n; i++)
        {
            if (bin_s[i])
            {
                if (ord.size() && ord.top() == '[')
                    ord.pop();
                else
                    ord.push('[');

                if (ord.empty())
                {
                    seqs[index].r = i;
                    seqs[index++].t = 1;
                }
            }
            else
            {
                if (ord.size() && ord.top() == '(')
                    ord.pop();
                else
                    ord.push('(');

                if (ord.empty())
                {
                    seqs[index].r = i;
                    seqs[index++].t = 0;
                }
            }
        }
        seqs[0].l = 0;
        for (int i = 1; i < index; i++)
            seqs[i].l = seqs[i - 1].r + 1;

        int cnts[2] = {0, 0};
        for (int i = 0; i < index; i++)
            cnts[seqs[i].t]++;

        if (cnts[0] > 1 || cnts[1] > 1)
            cout << "No\n";
        else
            cout << "Yes\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 0ms
memory: 3504kb

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
](]](([])[

result:

wrong output format YES or NO expected, but ](]](([])[ found [45th token]