QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276199#7894. Many Many Headssunshine123WA 1ms5640kbC++202.1kb2023-12-05 18:01:252023-12-05 18:01:26

Judging History

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

  • [2023-12-05 18:01:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5640kb
  • [2023-12-05 18:01:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define mp make_pair
#define PII pair<int, int>
const int maxn = 1e6 + 5;
int n;
int a[maxn];
int q[maxn];

void solve()
{
    string s;
    cin >> s;
    int n = s.size();
    string tmp1 = "*", tmp2 = "*";
    int tot = 0;
    string cc;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(' || s[i] == ')')
            a[i] = 0, cc += '0';
        else
            a[i] = 1, cc += '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;
    }
    string tmp = "";
    q[++tot] = a[0];
    tmp += cc[0];
    for (int i = 1; i < n; i++)
    {
        tmp = tmp + cc[i];
        if (a[i] != q[tot] || tot == 0)
        {
            q[++tot] = a[i];
        }
        else
        {
            tot -= 1;
        }
        if (tot == 0)
        {
            if (tmp == tmp1 || tmp == tmp2)
            {
                cout << "No" << endl;
                return;
            }
            else
            {
                if (tmp1 != "*" && tmp2 != "*")
                {
                    tmp2 = tmp1;
                    tmp1 = tmp;
                    tmp.clear();
                }
                else if (tmp1 == "*" && tmp2 == "*")
                {
                    tmp1 = tmp;
                    tmp.clear();
                }
                else
                {
                    tmp2 = tmp, tmp.clear();
                }
            }
        }
    }
    cout << "Yes" << endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    // t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
/*
6
))
((()
[()]
()[()]()
([()])
([])([])

*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

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

input:

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

output:

Yes
Yes

result:

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