QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624943#7894. Many Many HeadsE7k#WA 5ms3776kbC++201.9kb2024-10-09 16:58:062024-10-09 16:58:06

Judging History

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

  • [2024-10-09 16:58:06]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3776kb
  • [2024-10-09 16:58:06]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define gcd __gcd
using namespace std;
typedef pair<int,int> pii;
const int INF = 9e18;
const int inf = 2e9;

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t --)
    {
        string s;
        cin >> s;
        s = " " + s;
        vector<int> cnt(2);
        for(int i = 0;i < s.size();i ++)
        {
            if(s[i] == '(' || s[i] == ')') cnt[0] ++ ;
            if(s[i] == '[' || s[i] == ']') cnt[1] ++;
        }
        
        if((cnt[0] & 1) || (cnt[1] & 1))
        {
            cout << "Yes\n";
            continue;
        }
        int ok = 0;
        int n = s.size();
        vector<int> q(n + 1);
        int top = 0;
        for(int i = 1;i < s.size();i ++)
        {
            if(s[i] == ')' || s[i] == '(')
            {
                if(top != 0 && q[top] == '(')
                {
                    ok --;
                    if(ok == 0) q[++top] = ')';
                    else top --;
                }
                else
                {
                    ok ++;
                    q[++top] = '(';
                }
            }
            else
            {
                if(top != 0 && q[top] == '[')
                {
                    ok --;
                    if(ok == 0) q[++top] = ']';
                    else top --;
                }
                else
                {
                    ok ++;
                    q[++top] = '[';
                }
            }
        }
        cnt[0] = cnt[1] = 0;
        // cout << top << endl;
        for(int i = 1;i <= top;i ++)
        {
            // printf("%c",q[i]);
            if(q[i] == '(' || q[i] == ')') cnt[0] ++;
            else cnt[1] ++;
        }
        if(cnt[0] >= 4 || cnt[1] >= 4) cout << "No\n";
        else cout << "Yes\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5ms
memory: 3616kb

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]