QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570132#7894. Many Many Headsmhw#WA 0ms3752kbC++231.0kb2024-09-17 14:07:442024-09-17 14:07:44

Judging History

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

  • [2024-09-17 14:07:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2024-09-17 14:07:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
void solve()
{
    string s;
    cin >> s;
    int n = s.size(), f = 1;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(' || s[i] == ')') s[i] = '0';
        else s[i] = '1';
    }
    for (int i = 0; i + 3 < n; i++)
    {
        if (s[i] == s[i + 1] && s[i] == s[i + 2] && s[i] == s[i + 3]) f = 0;
    }
    int l = 0, r = n - 1;
    while(l < r)
    {
        if (s[l] != s[r]) 
        {
            if (s[l] == s[l + 1]) l += 2; 
            else if (s[r] == s[r - 1]) r -= 2;
            else l++, r--;
        }
        else 
        {
            if (l + 1 >= r - 1) break;
            if (s[l + 1] == s[r - 1] && s[l] == s[l + 1]) 
            {
                f = 0;
                break;
            }
            else l++, r--;
        }
    }
    if (f) cout << "Yes\n";
    else cout << "No\n";
}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
}

/*
1
[]()[]()
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3752kb

input:

2
(([([[([
]]))])]])]

output:

Yes
Yes

result:

wrong answer expected NO, found YES [2nd token]