QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#314028 | #7894. Many Many Heads | WRuperD | WA | 0ms | 3732kb | C++14 | 2.1kb | 2024-01-25 11:29:08 | 2024-01-25 11:29:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 7;
#define int long long
#define pb emplace_back
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline void write(int x){if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
void solve(){
string s;
cin>>s;
int n = s.length();
s = " " + s;
stack <int> stc;
for(int i = 1; i <= n; i++){
if(s[i] == ')' or s[i] == '('){
if(stc.empty()) stc.push(1), s[i] = '(';
else if(stc.top() == 1) stc.pop(), s[i] = ')';
else stc.push(1), s[i] = '(';
}
if(s[i] == '[' or s[i] == ']'){
if(stc.empty()) stc.push(2), s[i] = '[';
else if(stc.top() == 2) stc.pop(), s[i] = ']';
else stc.push(2), s[i] = '[';
}
}
bool fl = 1;
int mk = 1;
for(int i = 1; i <= n; i++){
if(s[i] == '('){
if(fl) stc.push(1);
else{
puts("No");
return ;
}
}
if(s[i] == ')'){
if(stc.top() != 1){
puts("No");
return ;
}
stc.pop();
fl = 0;
}
if(s[i] == '['){
if(fl) stc.push(2);
else{
puts("No");
return ;
}
}
if(s[i] == ']'){
if(stc.top() != 2){
puts("No");
return ;
}
stc.pop();
fl = 0;
}
if(stc.empty()) {
mk = i + 1;
}
}
if(!stc.empty()) {
puts("No");
return ;
}
fl = 1;
for(int i = mk + 1; i <= n; i++){
if(s[i] == '('){
if(fl) stc.push(1);
else{
puts("No");
return ;
}
}
if(s[i] == ')'){
if(stc.top() != 1){
puts("No");
return ;
}
stc.pop();
fl = 0;
}
if(s[i] == '['){
if(fl) stc.push(2);
else{
puts("No");
return ;
}
}
if(s[i] == ']'){
if(stc.top() != 2){
puts("No");
return ;
}
stc.pop();
fl = 0;
}
if(stc.empty()) {
mk = i + 1;
}
}
if(mk <= n){
puts("No");
}else{
puts("Yes");
}
}
signed main(){
int t = read();
while(t--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
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: 3592kb
input:
2 (([([[([ ]]))])]])]
output:
No No
result:
wrong answer expected YES, found NO [1st token]