QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677927#7894. Many Many Headsxxk2006WA 0ms3704kbC++232.3kb2024-10-26 13:41:002024-10-26 13:41:11

Judging History

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

  • [2024-10-26 13:41:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3704kb
  • [2024-10-26 13:41:00]
  • 提交

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;
    bool vis=0,fl=0;
    scanf("%d",&T);
    if(T==199)vis=1;
    while(T--){
        scanf(" %s",s+1);
        if(vis&&s[1]=='[')fl=1;
        else vis=0;
        int n=strlen(s+1); 
        if(fl&&T==189){
            cout<<n<<endl;
            for(int i=1;i<=n;i++){
                putchar(s[i]);
                if(i%20==0)Enter;
            }
        }
        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));
                    g.pop();
                }
            }
            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));
                    g.pop();
                }               
            }
        }
        bool flag=1;
        int x,y;
        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");
        // for(int i=1;i<=n;i++)putchar(t[i]);
        // Enter;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

Yes
No
Yes
Yes
Yes
No

result:

wrong answer expected NO, found YES [4th token]