QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276199 | #7894. Many Many Heads | sunshine123 | WA | 1ms | 5640kb | C++20 | 2.1kb | 2023-12-05 18:01:25 | 2023-12-05 18:01:26 |
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 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
))
((()
[()]
()[()]()
([()])
([])([])
*/
Details
Tip: Click on the bar to expand more detailed information
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]