QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756162 | #7894. Many Many Heads | Loxilante | WA | 0ms | 3624kb | C++20 | 1.6kb | 2024-11-16 19:12:18 | 2024-11-16 19:12:22 |
Judging History
answer
#define F_C
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define int ll
using namespace std;
typedef long long ll;
template<typename tn = int> tn next(void) { tn k; cin>>k; return k; }
#ifndef LOCAL
#define D(...) 0
#endif
bool check(string s)
{
rep(r, s.size()/2, s.size())
{
int l = s.size()-r-1;
if (s[l] != s[r]) return 1;
if (l != r-1 && s[r] == s[r-1]) return D(s), 0;
}
return 1;
}
signed main(void)
{
#ifdef LOCAL
// freopen("C:\\Users\\Loxil\\Desktop\\IN.txt", "r", stdin);
// freopen("C:\\Users\\Loxil\\Desktop\\OUT.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int T = next();
while(T--)
{
string str = next<string>(), s;
stack<int> st;
vector<string> v;
for(auto ch: str)
{
int t = ch == '(' || ch == ')' ? 0 : 1;
s += t+'0';
if (st.size() && st.top() == t) st.pop();
else st.push(t);
if (st.empty()) v.push_back(s), s.clear();
}
bool yes = check(str);
rep(i, 1, v.size())
{
yes &= check(v[i-1]+v[i]);
if (i+1 < v.size()) yes &= check(v[i-1]+v[i]+v[i+1]);
}
if (yes) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
/*
0110 0110 0110
112112
([([])]([]))[([()])]
[][()]()[][()]()
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 3624kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]