QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#626244 | #7894. Many Many Heads | L_ty | WA | 1ms | 3828kb | C++17 | 1.9kb | 2024-10-10 01:04:04 | 2024-10-10 01:04:05 |
Judging History
answer
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int N = 1e5 + 10;
char s[N];
void solve(){
cin >> s + 1;
int n = strlen(s + 1);
vector<int> v(n + 1);
vector<int> dis(n + 1);
vector<pair<int,int>> st;
map<int, vector<int>> mp;
for (int i = 1;i<=n;i++){
if(s[i]==')'||s[i]=='(')
v[i] = 1,mp[1].push_back(i);
else
v[i] = 2,mp[2].push_back(i);
}
for (int i = 1; i <= 2;i++){
for (int j = 0; j < mp[i].size();j++){
dis[mp[i][j]] = mp[i][mp[i].size() - 1 - j];
// cout << mp[i][j] << " " << mp[i][mp[i].size() - 1 - j] << " " << dis[i] << endl;
}
}
for (int i = 1; i <= n;i++){
if (st.empty())
st.push_back(make_pair(i, v[i]));
else{
if(v[i]==st.back().second){
if(i!=dis[st.back().first]){
cout << "No" << endl;
return;
}
else {
st.pop_back();
}
}
else{
st.push_back(make_pair(i, v[i]));
}
}
}
st.clear();
for (int i = n; i >=1;i--){
if (st.empty())
st.push_back(make_pair(i, v[i]));
else{
if(v[i]==st.back().second){
if(i!=dis[st.back().first]){
cout << "No" << endl;
return;
}
else {
st.pop_back();
}
}
else{
st.push_back(make_pair(i, v[i]));
}
}
}
cout << "Yes" << endl;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3828kb
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: 3532kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]