玄学错误囚条,玄关
查看原帖
玄学错误囚条,玄关
1059841
Bzh_2024楼主2024/3/30 14:47
#include<bits/stdc++.h>
#include<assert.h>
#include<map>
#include<set>
using namespace std;
#define f first
#define s second
#define re register
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef unsigned int uint;
typedef unsigned long long ull;
int t,n,ans,temp;
char res[100005],op[100005];
inline void work(){
    int cur=0;
    ans=0;
    stack<pair<int,char>> st;
    map<char,int> cnt;
    for(int i=1;i<=26;i++) cnt['a'+i-1]=0;
    string tttt;
    getline(cin,tttt);
    for(int i=1;i<=n;i++){
        string s;
        getline(cin,s);
        for(int j=0;j<s.size();j++) op[j+1]=s[j];
        if(op[1]=='E'){
            if(st.empty()){
                ans=-1;
                for(int j=i+1;j<=n;j++) getline(cin,s);
                return;
            }
            else{
                auto tmp=st.top();
                st.pop();
                if(tmp.f==1) cur--;
                else if(tmp.f!=0) cur=-tmp.f;
                cnt[tmp.s]=0;
            }
        }
        else if(op[1]=='F'){
            char ch=op[3];
            if(cnt[ch]){
                ans=-1;
                for(int j=i+1;j<=n;j++) getline(cin,s);
                return;
            }
            else{
                cnt[ch]=1;
                int num1=0,num2=0;
                int pos=5;
                if(op[pos]=='n'){
                    st.push({-cur,ch});
                    cur-=1<<20;
                }
                else{
                    while(op[pos]!=' ') num1=num1*10+op[pos++]-'0';
                    pos++;
                    if(op[pos]=='n'){
                        st.push({1,ch});
                        cur++;
                    }
                    else{
                        while(op[pos]!=' ') num2=num2*10+op[pos++]-'0';
                        if(num1>num2){
                            st.push({-cur,ch});
                            cur-=1<<20;
                        }
                        else st.push({0,ch});
                    }
                }
            }
        }
        ans=max(ans,cur);
    }
    if(!st.empty()) ans=-1;
}
int main(){
    scanf("%d",&t);
    while(t--){
        scanf("%d%s",&n,res+1);
        if(res[3]!='1') temp=res[5]-'0';
        else temp=0;
        work();
        if(ans==-1) puts("ERR");
        else if(ans==temp) puts("Yes");
        else puts("No");
    }
}

测试数据自测能跑过,然而 RE on 1# ~10#

2024/3/30 14:47
加载中...