QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410178 | #7894. Many Many Heads | AC_2002 | TL | 3ms | 7636kb | C++20 | 1.5kb | 2024-05-13 17:35:50 | 2024-05-13 17:35:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int a[1000010];
void solve() {
string s;
cin >> s;
stack<char> st;
int b[2][500010] = {0};
int sum1 = 0, sum2 = 0, temp1 = 0, temp2 = 0;
if (s[0] == '(' || s[0] == ')') sum1 ++, a[0] = 1, st.push('(');
else sum2 ++, a[0] = 2, st.push('[');
for (int i = 1; i < s.size(); i ++ ) {
if (s[i] == '(' || s[i] == ')') {
if (st.size() == 0) {
st.push('(');
a[i] = 1;
}
else if (st.top() == '(') a[i] = -1, st.pop();
else a[i] = 1, st.push('(');
} else {
if (st.size() == 0) {
st.push('[');
a[i] = 2;
}
else if (st.top() == '[') a[i] = -2, st.pop();
else a[i] = 2, st.push('[');
}
}
// memset(b, 0, sizeof b);
int d = 0;
for (int i = 0; i < s.size(); i ++ ) {
if (a[i] == 1) {
d ++ ;
if (b[0][d] == 1) {
cout << "No" << endl;
return;
}
b[0][d] = 1;
} else if (a[i] == -1) d -- ;
else if (a[i] == 2) {
d ++ ;
if (b[1][d] == 1) {
cout << "No" << endl;
return;
}
b[1][d] = 1;
} else if (a[i] == -2) d -- ;
}
cout << "YES" << endl;
}
signed main() {
int _;
cin >> _;
while (_ -- ) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 7636kb
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: 0
Accepted
time: 0ms
memory: 7436kb
input:
2 (([([[([ ]]))])]])]
output:
YES No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Time Limit Exceeded
input:
15134 ][ )( )([[ [)([ )][) ]])( ([]([] ]]))][ [([](] ()[))] ][(]]( ([()[) ()[](( [)([)( ]]([[)]] )[()])]] ))[](([] ](([((]] ))[)][)[ [)])([(] [()[]))[ )][(]()] [[((]()] ((]])[[) ])(](]]) )]]()[]( ([)[])]) [[)[()]( ([[)[[() [[)([])) [)[[)[() ))[(([)( ()][)[](]] [()]([[([[ )[]))][)][ )]([]([(][ [])])(...
output:
YES YES YES YES YES YES YES No YES YES YES YES No YES No YES No No YES YES No YES No No YES No YES YES No No YES No No No No YES No No No No No No YES No No YES YES No No No YES No No No No YES No No No YES YES No No YES No No No No No No YES No No No No No No No No No No YES No No No No No No No No...