关于数组越界可能性疑问

P3952 [NOIP2017 提高组] 时间复杂度

IkunFriendsChat @ 2024-10-02 22:00:58

RT,本人AC代码如下:

#include<bits/stdc++.h>
using namespace std;
int T;
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        int nm[29]={0},g[29]={0},lp[114]={0};
        string s1,s2;
        int a;string tm;
        cin>>a>>tm;
        int inde=0;int loopn=0,k=0,loopnow=0,n=0,m=0;
        for(int i=4;i<tm.size();i++)if(isdigit(tm[i]))inde=(inde<<3)+(inde<<1)+tm[i]-'0';
        int fl=1;//printf("%d ",inde);
        while(a)
        {
            a--;
            cin>>s1;
            if(s1=="F")
            {
                ++loopn;cin>>s1;
                if(nm[s1[0]-'a'+1])loopn=-1;
                nm[s1[0]-'a'+1]=1;g[loopn]=s1[0]-'a'+1;
                cin>>s1>>s2;
                if(s1!="n"&&s2=="n"&&!k)loopnow++,lp[loopn]=1;
                else if(((s1.size()==s2.size()&&s1>s2)||(s1.size()>s2.size())||(s1[0]=='n'&&s2[0]!='n'))&&!k)k=1,n=loopn;
                m=max(m,loopnow);
            }
            else
            {
                m=max(m,loopnow);nm[g[loopn]]=0;
                if(lp[loopn]==1)loopnow--,lp[loopn]=0;
                loopn--;
                if(n>0&&loopn<n)k=0,n=0;
            }
            if(loopn==-1)fl=0;
        }
        if(loopn!=0||!fl)printf("ERR\n");
        else
        {
            if(m==inde)printf("Yes\n");
            else printf("No\n");
        }
    }
}

其中

if(nm[s1[0]-'a'+1])loopn=-1;
nm[s1[0]-'a'+1]=1;g[loopn]=s1[0]-'a'+1;

两行不存在RE的可能性吗?求助。


|