QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#612999 | #7894. Many Many Heads | wsxcb# | WA | 1ms | 3820kb | C++17 | 959b | 2024-10-05 13:24:39 | 2024-10-05 13:24:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define fi first
#define se second
const int N = 1e5 + 5;
int a[N];
char ch[N];
void solve() {
string s;
cin >> s;
int n = s.size();
s = "#" + s;
for (int i = 1; i <= n; i++) {
if (s[i] == '(' || s[i] == ')')
s[i] = '1';
else
s[i] = '0';
}
//cout << s << '\n';
stack<char>st;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if ((int)st.size() == 0) {
cnt++;
if (s[i] == s[i - 1]) {
cout << "No\n";
return ;
}
if (cnt == 3) {
cout << "No\n";
return ;
}
st.push(s[i]);
} else if (s[i] == st.top()) {
st.pop();
} else {
st.push(s[i]);
}
}
if (st.size() == 0)
cout << "Yes\n";
else
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ch[0] = '#';
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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: 3756kb
input:
2 (([([[([ ]]))])]])]
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3820kb
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 Yes Yes Yes No No No Yes No No No No Yes No No No Yes Yes Yes No Yes No No No No No No Yes No No No No No No No No No No Yes Yes No No No No No No...
result:
wrong answer expected NO, found YES [45th token]