QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276176#7894. Many Many Headssunshine123WA 0ms3540kbC++201.4kb2023-12-05 17:27:472023-12-05 17:27:48

Judging History

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

  • [2023-12-05 17:27:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3540kb
  • [2023-12-05 17:27:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, m;
int a[N];
#define PII pair<int, int>
vector<PII> ve;
void solve()
{
    string s;
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++)
        if (s[i] == '(' || s[i] == ')')
            a[i] = 0;
        else
            a[i] = 1;
    if (n == 2)
    {
        cout << "Yes" << endl;
        return;
    }
    if (n == 4)
    {
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += a[i];
        if (sum == 2)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return;
    }
    int f = 0;
    int cnt = 0;
    char x;
    for (int i = 1; i < n; i++)
    {
        if (a[i] == a[i - 1])
            cnt++;
        if (cnt > 2)
        {
            puts("No");
            return;
        }
        if (a[i] != a[i - 1])
        {
            f = 0;
            continue;
        }
        else if (a[i] == a[i - 1] && f == 0)
            f = 1;
        else if (a[i] == a[i - 1] && f == 1)
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    return;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
No
Yes
Yes
No
No

result:

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