QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#650638 | #7894. Many Many Heads | absabs | RE | 0ms | 0kb | C++23 | 3.4kb | 2024-10-18 15:57:08 | 2024-10-18 15:57:10 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ms(x, y) memset(x, y, sizeof x);
#define debug(x) cout << #x << " = " << x << endl;
#define ios ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fre \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const double esp = 1e-6;
const ull MOD1 = 1610612741;
const ull MOD2 = 805306457;
const ull BASE1 = 1331;
const ull BASE2 = 131;
#define pre(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
char *p1, *p2, buf[100000]; // 快读和同步流二者只能选一个
#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
int read()
{
int x = 0, f = 1;
char ch = nc();
while (ch < 48 || ch > 57)
{
if (ch == '-')
f = -1;
ch = nc();
}
while (ch >= 48 && ch <= 57)
x = x * 10 + ch - 48, ch = nc();
return x * f;
}
void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
string s;
int change(char c)
{
if(c == '(' || c == ')') return 0;
return 1;
}
void solve()
{
cin >> s;
// cout<<s<<endl;
string str;
stack<char> st;
// return;
for(auto L : s)
{
char a='(',b=')',c='[',d=']';
// cout<<L<<endl;
if(st.empty()) {
st.push(L);
if(change(L))str+=c;
else str+=a;
continue;
}
if(change(st.top()) == change(L))
{
int tp = change(st.top());
if(tp == 0)
str += ')';
else str += ']';
st.pop();
}
else {
st.push(L);
if(change(L))str+=c;
else str+=a;
continue;
}
}
// cout<<str<<endl;
// return;
if(!st.empty())
{
cout << "No" << endl;
return ;
}
int f = 0;
for(int i=0;i<str.size();i++)
{
if(i + 1 < str.size() && str[i] == ')' && str[i + 1] == '(')
f = 1;
else if(i + 1 < str.size() && str[i] == ']' && str[i + 1] == '[')
f = 1;
}
vector<int>res;
for(int i=0;i<s.size();i++){
if(change(str[i])==change(str[i+1]))res.push_back(i);
}
int tp=-1;
for(auto a:res){
// cout<<a<<endl;
int l=a,r=a+1;
while(l>2&&r<s.size()-2){
if(str[l-2]==')'&&str[l-1]=='['&&str[r+1]==']'&&str[r+2]=='(')f=1;
else if(str[l-2]==']'&&str[l-1]=='('&&str[r+1]==')'&&str[r+2]=='[')f=1;
// cout<<str[l-2]<<" "<<str[l-1]<<" "<<str[r+1]<<" "<<str[r+2]<<endl;
l--;
r++;
if(l==tp||r==s.size())break;
tp=l;
}
}
for(int i=2;i<s.size()-3;i++){
int l=i;
int r=i+1;
if(str[l-1]==')'&&str[l]=='['&&str[r]==']'&&str[r+1]=='(')f=1;
else if(str[l-1]==']'&&str[l]=='('&&str[r]==')'&&str[r+1]=='[')f=1;
}
if(f) cout << "No" <<endl;
else cout << "Yes" << endl;
}
// #define LOCAL
signed main()
{
// ios
// fre
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
#endif
int t = 1;
cin >> t;
while (t--)
solve();
#ifdef LOCAL
auto end = std::chrono::high_resolution_clock::now();
cout << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])