QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#613304 | #7894. Many Many Heads | wsxcb# | WA | 3ms | 3824kb | C++17 | 1.0kb | 2024-10-05 13:54:06 | 2024-10-05 13:54:13 |
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;
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;
char last = '#';
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 ;
}
last = '#';
st.push(s[i]);
} else if (s[i] == st.top()) {
if (s[i] == last) {
cout << "No\n";
return ;
}
last = s[i];
st.pop();
} else {
st.push(s[i]);
}
//cout << st.size() << ' ';
}
if (st.size() == 0)
cout << "Yes\n";
else
cout << "No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(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: 0ms
memory: 3752kb
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: 3528kb
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: 3ms
memory: 3824kb
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]