QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394798 | #7894. Many Many Heads | ucup-team3294# | WA | 0ms | 3812kb | C++23 | 989b | 2024-04-20 19:44:56 | 2024-04-20 19:44:57 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define PII pair<int,int>
#define x first
#define y second
using namespace std;
const int N=1e6+5;
const int mod=1e9+7;
void solve(){
int n;
string s;
cin>>s;
n=s.size();
s=" "+s;
stack<int> st;
vector<int> c(3),b(3),k(3);
for(int i=n;i>=1;i--){
int t;
if(s[i]=='('||s[i]==')') t=1;
else t=2;
if(st.size()){
if(st.top()==t){
b[t]++;
k[t]--;
st.pop();
}else if(k[t]){
c[t]++;
k[t]++;
st.push(t);
}else{
k[t]++;
st.push(t);
}
}else{
k[t]++;
st.push(t);
}
}
// for(int i=1;i<=2;i++){
// cout<<c[i]<<" ";
// }
// cout<<endl;
// for(int i=1;i<=2;i++){
// cout<<b[i]<<" ";
// }
// cout<<endl;
if(c[1]==max(b[1]-1,0LL)&&c[2]==max(b[2]-1,0LL)){
puts("Yes");
}else{
puts("No");
}
}
signed 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: 3812kb
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: 3652kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]