QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#316284#7894. Many Many HeadsKotomiWA 6ms3608kbC++20866b2024-01-27 19:17:542024-01-27 19:17:55

Judging History

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

  • [2024-01-27 19:17:55]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3608kb
  • [2024-01-27 19:17:54]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>

using namespace std;

bool solve() {
    string s;
    cin >> s;
    unordered_map<char, int> kind;
    kind['('] = kind[')'] = 1;
    kind['['] = kind[']'] = 2;
    int n = s.size();
    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0, j = i; i < n; ++ i) {
        while (j < n && kind[s[i]] == kind[s[j]]) ++ j;
        int len = j - i;
        if (len >= 3) return false;
        if (len == 2) {
            if (kind[s[i]] == 1) cnt1 ++;
            else cnt2 ++;
            if (cnt1 >= 2 || cnt2 >= 2) return false;
        }
        i = j - 1;
    }
    return true;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int T; cin >> T;
    while (T --) {
        cout << (solve() ? "Yes": "No") << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 6ms
memory: 3584kb

input:

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

output:

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

result:

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