QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276176 | #7894. Many Many Heads | sunshine123 | WA | 0ms | 3540kb | C++20 | 1.4kb | 2023-12-05 17:27:47 | 2023-12-05 17:27:48 |
Judging History
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]