跳到正文

个人记录

时间复杂度

一濑红莲约 5 分钟
原文
文章信息与版本

文章信息

发布
2018年12月23日
收录
2026年1月29日
更新
2026年11月9日
篇幅
约 5 分钟

版本

  1. v2当前
  2. v1
C++
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int t,n=466;
int main()
{
//	freopen("a.in","r",stdin);
    cin>>t;
    while(t--)
    {
        int used[500];
        memset(used,0,sizeof(used));
        bool err=false;
        int h;
        cin>>h;
        if(h%2) err=true;
        char tm[15];
        cin>>tm;
        int tim=1;
        char w[200][10][2];
        int zhan1=0,zhan2=0;
        int zhan[810],zhana[810],zhann[810];
        bool t=false;
        int f=0,e=0;
        for(int i=1;i<=h;i++)
        {
            cin>>w[i][1][0];
            if(w[i][1][0]=='F'){
                f++;
                cin>>w[i][2]>>w[i][3]>>w[i][4];
                if(used[w[i][2][0]]==1) err=true;
                used[w[i][2][0]]=1;
                zhana[++zhan1]=w[i][2][0];
                if(w[i][3][0]=='n') zhann[zhan1]=n;
                else if(strlen(w[i][3])==1) zhann[zhan1]=w[i][3][0]-48;
                else zhann[zhan1]=(w[i][3][0]-48)*10+w[i][3][1]-48;
                if(w[i][4][0]=='n') zhan[zhan1]=n;
                else if(strlen(w[i][4])==1) zhan[zhan1]=w[i][4][0]-48;
                else zhan[zhan1]=(w[i][4][0]-48)*10+w[i][4][1]-48;
            }
            if(w[i][1][0]=='E'){
                e++;
                int timz=1;
                //cout<<zhan1<<endl;
                used[zhana[zhan1]]=0;
                for(int j=1;j<=zhan1;j++)
                {
                    if(zhan[j]<zhann[j]) break;
                    if(zhan[j]==n&&zhan[j]!=zhann[j])
                    {
                        if(timz==1){timz=n;}
                        else if(timz==n) {timz=2;}
                        else  timz++;
                    }
                    else if(zhan[j]>='0'&&zhan[j]<='9'){
                        continue;
                    }
                }
                if(tim==1) tim=timz;
                else if(tim==n&&timz>=2) tim=timz;
                else if(timz>=tim&&timz!=n) tim=timz;
                zhan1--;
                if(zhan1<0) err=true;
            }
        }
        //cout<<tim<<endl;
        if(e!=f) err=1;
        if(err==1) {cout<<"ERR\n";continue;}
        if(tim==n&&tm[2]=='n'&&tm[4]=='1') {cout<<"Yes"<<endl;continue;}
        if(tim==1&&tm[2]=='1'){cout<<"Yes"<<endl;continue;}
        if(tim==(tm[4]-48)&&tm[5]==')'&&tim!=1){cout<<"Yes"<<endl;continue;}
        if(tm[5]>='0'&&tm[5]<='9'&&tim==((tm[4]-48)*10+tm[5]-48)) {cout<<"Yes"<<endl;continue;}
        cout<<"No"<<endl;
    }
    return 0;
}
原文