QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276113 | #7894. Many Many Heads | sunshine123 | WA | 1ms | 5828kb | C++20 | 1.4kb | 2023-12-05 16:36:22 | 2023-12-05 16:36:23 |
Judging History
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]