QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#314316#7894. Many Many HeadswdwWA 4ms3572kbC++142.6kb2024-01-25 15:32:322024-01-25 15:32:33

Judging History

你现在查看的是最新测评结果

  • [2024-01-25 15:32:33]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3572kb
  • [2024-01-25 15:32:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N=1205+5;
const double eps=1e-10;
const int mod=1e9;
#define endl '\n'
void solve() {
    string s;
    cin>>s;
    int f=0;
    int f2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==')'||s[i]=='('){
            f2=0;
            f++;
            if(f==3){
                cout<<"No"<<endl;
                return;
            }
        }else if(s[i]=='['||s[i]==']'){
            f=0;
            f2++;
            if(f2==3){
                cout<<"No"<<endl;
                return;
            }
        }
    }
   /* stack<int>q;
    for(int i=0;i<s.size();i++){
        if(!q.empty()){
            if(q.top()==1){
                if(s[i]==')'||s[i]=='('){
                    q.pop();
                }else{
                    q.push(0);
                }
            }else{
                if(s[i]==')'||s[i]=='('){
                    q.push(1);
                }else{
                    q.pop();
                }
            }
        }
    }
    if(!q.empty()){
        cout<<"No"<<endl;
        return;
    }*/
   stack<int>q1;
    vector<int>a(s.size()+5);
    int x=1;
    int f1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='('||s[i]==')'){
            a[x]++;
            if(a[x]==3){
                cout<<"No"<<endl;
                return;
            }
            if(!q1.empty()&&q1.top()==1){
                q1.pop();
            }else{
                q1.push(1);
            }
        }else{
            if(!q1.empty()&&q1.top()==0){
                q1.pop();
                x--;
            }else{
                x++;
                q1.push(0);
            }
        }
    }
    int f3=0;
    int x2=1;
    vector<int>a2(s.size()+5);
    stack<int>q;
    for(int i=0;i<s.size();i++){
        if(s[i]=='['||s[i]==']'){
            a2[x2]++;
            if(a2[x2]==3){
                cout<<"No"<<endl;
                return;
            }
            if(!q.empty()&&q.top()==0){
                q.pop();
            }else{
                q.push(0);
            }
        }else{
            if(!q.empty()&&q.top()==1){
                q.pop();
                x2--;
            }else{
                x2++;
                q.push(1);
            }
        }
    }
    cout<<"Yes"<<endl;

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    // cout<<fixed<<setprecision(2);
    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: 3520kb

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: 0
Accepted
time: 0ms
memory: 3572kb

input:

2
(([([[([
]]))])]])]

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 3524kb

input:

15134
][
)(
)([[
[)([
)][)
]])(
([]([]
]]))][
[([](]
()[))]
][(]](
([()[)
()[]((
[)([)(
]]([[)]]
)[()])]]
))[](([]
](([((]]
))[)][)[
[)])([(]
[()[]))[
)][(]()]
[[((]()]
((]])[[)
])(](]])
)]]()[](
([)[])])
[[)[()](
([[)[[()
[[)([]))
[)[[)[()
))[(([)(
()][)[](]]
[()]([[([[
)[]))][)][
)]([]([(][
[])])(...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
Yes
No
No
Yes
Yes
No
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
...

result:

wrong answer expected YES, found NO [43rd token]