QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398490 | #7894. Many Many Heads | xiaole | WA | 4ms | 3656kb | C++23 | 917b | 2024-04-25 13:44:38 | 2024-04-25 13:44:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
void solve(){
string s;cin>>s;
ll n=s.size();
s=" "+s;
for (ll i = 1; i <= n; i++)
{
if(s[i]=='(' or s[i]==')') s[i]='1';
else s[i]='2';
}
for (ll i = 1; i < n-1; i++)
{
if(s[i]==s[i+1] and s[i]==s[i+2]){
cout<<"No\n";
return;
}
}
ll cnt=0;
stack<char> st;st.push(s[1]);
for (ll i = 2; i <= n; i++)
{
if(st.size() and st.top()==s[i]) st.pop();
else st.push(s[i]);
if(st.size()==0)
cnt++;
}
if(cnt>2 or (cnt==2 and s[1]==s[n])) cout<<"No\n";
else{
cout<<"Yes\n";
}
}
int main(){
ios;ll _=1;cin>>_;
while (_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3560kb
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: 4ms
memory: 3656kb
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]