QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276113#7894. Many Many Headssunshine123WA 1ms5828kbC++201.4kb2023-12-05 16:36:222023-12-05 16:36:23

Judging History

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

  • [2023-12-05 16:36:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5828kb
  • [2023-12-05 16:36:22]
  • 提交

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 q[maxn];
int s[maxn];
void solve()
{
    string ss;
    cin >> ss;
    int n = ss.size();
    int tot = 0;
    int pos = 0;
    for (int i = 0; i < n; i++)
    {
        if (ss[i] == '(' || ss[i] == ')')
            s[i] = 1;
        else
            s[i] = 2;
    }
    q[++tot] = s[0];
    for (int i = 1; i < n; i++)
    {
        if (s[i] != q[tot])
        {
            q[++tot] = s[i];
        }
        else
        {
            tot -= 1;
        }
        if (tot == 0)
        {
            pos = i;
            break;
        }
    }
    int tot1 = 0;
    q[++tot1] = s[0];
    int flag = 0;
    for (int i = 1; i < n; i++)
    {
        if (s[i] != q[tot1])
        {
            q[++tot1] = s[i];
        }
        else
        {
            tot1 -= 1;
        }
        if (tot1 == 0 && i != pos)
        {
            flag = 1;
            break;
        }
    }
    if (flag)
        cout << "No" << endl;
    else
        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: 5828kb

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: 1ms
memory: 5824kb

input:

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

output:

No
No

result:

wrong answer expected YES, found NO [1st token]