[NOIP2017]时间复杂度
栈还原进入循环前的状态即可。
#include
using namespace std;
int sta[105],s2[105],top;
char s[15];
bool b[30],flag;
void read_res(int res){
int x,y;
while(res--){
scanf("%s",s+1);
if(s[1]=='F'){
scanf("%s%s%s",s+1,s+1,s+1);
}
}
}
int main(){
int t,tim,len;
scanf("%d",&t);
while(t--){
scanf("%d%s",&len,s+1);
tim=0;
if(s[3]=='n')
for(int i=5,l=strlen(s+1);iy){
s2[top]=-1-tot;
tot=-1;
}
else if(x<=100&&y==101){
if(tot!=-1){
++tot;
s2[top]=1;
}
else s2[top]=0;
}
else s2[top]=0;
ans=max(ans,tot);
}
else{
if(!top){
flag=false;
read_res(len);
break;
}
tot-=s2[top];
b[sta[top--]]=false;
}
}
if(!flag||top>0) printf("ERR\n");
else if(ans==tim) printf("Yes\n");
else printf("No\n");
}
return 0;
}