QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619231 | #7894. Many Many Heads | tsai | WA | 0ms | 4024kb | C++14 | 718b | 2024-10-07 13:34:49 | 2024-10-07 13:34:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 +50;
int trans[N];
int cnt[N];
void solve(){
stack<int>st;
string s;
cin>>s;
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;
trans[0] = 0;
for(int i = 0; i <= s.length(); i++){
if(!st.empty()){
if(trans[i] == trans[st.top()]){
st.pop(), cnt[st.top()]++;
if(cnt[st.top()] >= 2 || cnt[st.top()] >= 2) return printf("No"), void();
}
else st.push(i);
}
else st.push(i);
}
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: 3720kb
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: 4024kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]