QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619226 | #7894. Many Many Heads | tsai | WA | 0ms | 3788kb | C++14 | 978b | 2024-10-07 13:33:54 | 2024-10-07 13:33:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 +50;
int trans[N];
int cnt[3];
int booll[3]={0};
void solve(){
stack<int>st;
string s;
cin>>s;
booll[1]=booll[2]=0;
for(int i = 1; i <= s.length(); i++) trans[i] = (s[i-1] == '(' || s[i-1] == ')')? 1 : 2;
cnt [0] = cnt[1] = cnt[2] = 0;
int last = 0;
for(int i = 1; i <= s.length(); i++){
if(!st.empty()){
if(trans[i] == st.top()){
st.pop();last=trans[i];cnt[trans[i]]=1;
}else{
booll[last]=1;
last=0;
st.push(trans[i]);
}
if((cnt[1]>=1&&booll[1]==1)||(cnt[2]>=1&&booll[2]==1)) return printf("No"), void();
}else {
st.push(trans[i]);
booll[last]=1;
}
}
if((cnt[1]>=1&&booll[1]==1)||(cnt[2]>=1&&booll[2]==1)) return printf("No"), void();
printf("Yes");
}
int main(){
int t;
scanf("%d",&t);
while(t--){
solve();
if(t) printf("\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: 3708kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]