QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665292 | #7894. Many Many Heads | zyq_313 | WA | 1ms | 3568kb | C++14 | 1.4kb | 2024-10-22 11:02:15 | 2024-10-22 11:02:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define BUG cout << "HERE IS BUG\n"
const int N = 1e6 + 10;
string s;
void solve(){
cin >> s;
string c;
vector<char> v;
for (int i = 0; i < s.size(); i ++){
if (v.size() == 0){
if (s[i] == '(' || s[i] == ')'){
v.push_back('(');
c += '(';
}else{
v.push_back('[');
c += '[';
}
}else{
if (v.back() == '('){
if (s[i] == '(' || s[i] == ')'){
c += ')';
v.pop_back();
}else{
c += '[';
v.push_back('[');
}
}else if (v.back() == '['){
if (s[i] == '[' || s[i] == ']'){
c += ']';
v.pop_back();
}else{
c += '(';
v.push_back('(');
}
}
}
}
map<int, int> x, y;//x是() y是[]
int cnt1 = 0, cnt2 = 0;//cnt1是()的层数 cnt2是[]的层数
// cout << c << endl;
for (int i = 0; i < c.size(); i ++){
if (c[i] == '(') cnt1 ++;
else if (c[i] == '[') cnt2 ++;
else if (c[i] == ')'){
x[cnt1] ++;
if (x[cnt1] >= 2){
cout << "No\n";
return ;
}
y[cnt2] = 0;
cnt1 --;
}else if (c[i] == ']'){
y[cnt2] ++;
if (y[cnt2] >= 2){
cout << "No\n";
return ;
}
x[cnt1] = 0;
cnt2 --;
}
// cout << i << ' ' << cnt1 << ' ' << cnt2 << ' ' << endl;
}
cout << "Yes\n";
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t --) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: 3516kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]