QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363247 | #7894. Many Many Heads | OobugoO | RE | 0ms | 0kb | C++20 | 1.4kb | 2024-03-23 19:56:39 | 2024-03-23 19:56:40 |
answer
#include <bits/stdc++.h>
#define x first
#define y second
typedef long long ll;
int get(char c) {
if (c == '(' || c == ')') return 1;
else if (c == '[' || c == ']') return 2;
}
void solve() {
std::string s;
std::cin >> s;
int n = s.size();
std::vector<char> st(1, '#');
int now_dep = 1;
std::vector<int> dep;
std::vector<int> f;
for (int i = 0; i < n; i++) {
if (get(s[i]) == get(st.back())){
now_dep--;
dep.push_back(now_dep);
f.push_back(get(s[i]));
st.pop_back();
} else {
now_dep++;
st.push_back(s[i]);
}
}
int mx = *(std::max_element(dep.begin(), dep.end()));
std::vector<int> pre(mx + 1, 0);
std::vector<int> num(mx + 1, 0);
for (int i = 0; i < dep.size(); i++) {
if (pre[dep[i]] == f[i] || num[dep[i]] == 2) {
std::cout << "No\n";
return;
}
pre[dep[i]] = f[i];
num[dep[i]]++;
}
if (st.size() == 1) {
std::cout << "Yes\n";
} else {
std::cout << "No\n";
}
}
int main(){
#ifdef Onlion_Judge
freopen("IO/input.in", "r", stdin);
freopen("IO/output.out", "w", stdout);
// freopen("E:\\save work\\data\\4.in", "w", stdout);
#endif
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 )) ((() [()] ()[()]() ([()]) ([])([])