QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#618780 | #7894. Many Many Heads | sw7777 | WA | 0ms | 3844kb | C++17 | 1.6kb | 2024-10-07 10:12:08 | 2024-10-07 10:12:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f3f3f3f
#define pii pair<int, int>
#define endl '\n'
const int N=1e6+10;
const int N1=1e3+10;
const int mod=1e9+7;
void Atomatic_AC_machine(){
string s;cin>>s;
s=" "+s;
int l=1,r=s.size()-1;
string s1=s;
while(l<r){
// cout<<"1"<<s[l]<<" "<<s[r]<<endl;
if(s[l]=='('||s[l]==')') s[l]='(',s[r]=')';
else s[l]='[',s[r]=']';
l++,r--;
}
//cout<<s<<endl;
int ls=0,lb=0;
stack<int> st;
int lst=0;
for(int i=1;i<s1.size();i++){
if(s1[i]=='('||s1[i]==')'){
if(ls&&(lst==1||!lb)){
st.push(')');
ls--;
}else{
st.push('(');
ls++;
}
lst=1;
}else{
if(lb&&(lst==2||!ls)){
st.push(']');
lb--;
}else{
st.push('[');
lb++;
}
lst=2;
}
}
bool flag=0;
if(ls==0&&lb==0){
string tmp="";
while(st.size()){
tmp.push_back(st.top());
st.pop();
}
tmp.push_back(' ');
reverse(tmp.begin(),tmp.end());
if(tmp!=s) flag=1;
//cout<<tmp<<endl;
}
cout<<(flag?"No":"Yes")<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--){
Atomatic_AC_machine();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3844kb
input:
2 (([([[([ ]]))])]])]
output:
Yes Yes
result:
wrong answer expected NO, found YES [2nd token]