QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#643663 | #7894. Many Many Heads | Left0807 | WA | 0ms | 3600kb | C++20 | 1.9kb | 2024-10-15 22:45:31 | 2024-10-15 22:45:33 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int long long
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>;
int INF = 1e18;
const int MOD = 998244353;
const int N = 5e5 + 10;
const int LOG = 20;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[N];
void solve(){
string s;
cin >> s;
int n = s.size();
string t = "", st = "";
for(char& c : s){
if(c == ')') c = '(';
if(c == ']') c = '[';
if(st.back() == c){
st.pop_back();
if(c == '(') c = ')';
else c = ']';
} else{
st.push_back(c);
}
}
s = ' ' + s + ' ';
vector<int> st1, st2;
vector<int> pos(n+1);
for(int i = 1; i <= n; i++){
if(s[i] == '(') st1.push_back(i);
else if(s[i] == '[') st2.push_back(i);
else if(s[i] == ')'){
pos[st1.back()] = i;
st1.pop_back();
} else{
pos[st2.back()] = i;
st2.pop_back();
}
}
bool ok = true;
for(int i = 1; i <= n; i++){
if(s[i] == ')' && s[i+1] == '(') ok = false;
if(s[i] == ']' && s[i+1] == '[') ok = false;
if(pos[i] && s[i] == ')' && s[pos[i] + 1] == '(') ok = false;
if(pos[i] && s[i] == ']' && s[pos[i] + 1] == '[') ok = false;
}
if(ok) cout << "Yes\n";
else cout << "No\n";
}
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while(tt--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3600kb
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])
output:
Yes No Yes Yes Yes No
result:
wrong answer expected NO, found YES [4th token]