QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677727#7894. Many Many Headsxxk2006WA 0ms3932kbC++232.1kb2024-10-26 13:19:542024-10-26 13:19:55

Judging History

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

  • [2024-10-26 13:19:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3932kb
  • [2024-10-26 13:19:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
char s[100009],t[100009];
stack<pair<bool,int>> g;
vector<pair<int,int>> f;
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf(" %s",s+1);
        int n=strlen(s+1); 
        s[n+1]='$';
        f.clear();
        while(!g.empty())g.pop();
        for(int i=1;i<=n;i++){
            if(s[i]=='('||s[i]==')'){
                if(g.empty()||g.top().fi==1){
                    g.push(make_pair(0,i));
                    t[i]='(';
                }
                else{
                    t[i]=')';
                    f.pb(make_pair(g.top().se-1,i+1));
                }
            }
            else{
                if(g.empty()||g.top().fi==0){
                    g.push(make_pair(1,i));
                    t[i]='[';
                }
                else{
                    t[i]=']';
                    f.pb(make_pair(g.top().se-1,i+1));
                }               
            }
        }
        bool flag=1;
        int x,y;
        for(int i=0;i<f.size();i++){
            x=f[i].fi,y=f[i].se;
            if((t[x]==')'&&t[y]=='(')||(t[x]==']'&&t[y]=='[')){
                flag=0;
                break;
            }
        }
        for(int i=2;i<n;i++){
            if((t[i]==')'&&t[i+1]=='(')||(t[i]==']'&&t[i+1]=='[')){
                flag=0;
                break;
            }
        }
        if(flag)puts("Yes");
        else puts("No");
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3932kb

input:

6
))
((()
[()]
()[()]()
([()])
([])([])

output:

Yes
Yes
Yes
Yes
Yes
No

result:

wrong answer expected NO, found YES [2nd token]