记录编号 475271 评测结果 AAAAAAAAAA
题目名称 [NOIP 2017]时间复杂度 最终得分 100
用户昵称 Gravatar하루Kiev 是否通过 通过
代码语言 C++ 运行时间 0.160 s
提交时间 2017-11-15 11:15:06 内存使用 0.23 MiB
显示代码纯文本
# include <cstdio>
# include <algorithm>
# include <iostream>
# include <cmath>
# include <cstring>
# include <map>
# include <queue>
# include <cstdlib>
 
using namespace std;
 
void read(int &x){
	 x=0;char c=getchar();
	 while(c<'0'||c>'9') c=getchar();
	 while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();	 
}
 
int T,L,tail,tim,ans,qtim[1005],qflag[1005];
char s[15],a[15],b[15],opt;
string bl,q[1005];
bool ed,flag;
map<string,bool> mp;
 
int main(){
	freopen("2017complexity.in","r",stdin);
	freopen("2017complexity.out","w",stdout);
	read(T);
	while(T--){
		ed=0;flag=0;tail=0;
		ans=0,tim=0;mp.clear();
		read(L);scanf("%s",s);
		while(L--){
			  cin>>opt;
			  if(opt=='F'){
			  	 cin>>bl;
			  	 scanf("%s%s",a,b);
			  	 if(mp[bl]) ed=true;
			  	 mp[bl]=true;
			  	 q[++tail]=bl;
			  	 if(a[0]=='n'&&b[0]!='n') flag=true;
			  	 if(a[0]!='n'&&b[0]=='n'&&!flag) if(!flag) tim++;
			  	 qtim[tail]=tim;
			  	 qflag[tail]=flag;
			  	 if((a[0]!='n'&&b[0]!='n')||(a[0]=='n'&&b[0]=='n')){
			  	 	int fro=0,to=0,now1=0,now2=0;
			  	 	while(a[now1]>='0'&&a[now1]<='9') fro=fro*10+a[now1]-'0',now1++;
			  	 	while(b[now2]>='0'&&b[now2]<='9') to=to*10+b[now2]-'0',now2++;
			  	 	if(fro>to) flag=true;
			  	 }
			  }
			  else{
			  	 if(tail==0) {ed=true;continue;}
			  	 ans=max(ans,tim);
			  	 mp[q[tail]]=false;
			  	 tail--;
			  	 if(tail==0) tim=0,flag=0;
			  	 else tim=qtim[tail],flag=qflag[tail];
			  	 
			  }
		}
		if(tail!=0||ed==true) printf("ERR\n");
		else{
			if(s[2]=='1'){
				if(ans==0) printf("Yes\n");
				else printf("No\n");
			}
			else{ 
			   int Tim=0,now=4;
			   while(s[now]>='0'&&s[now]<='9') Tim=Tim*10+s[now]-'0',now++;
			   if(Tim==ans) printf("Yes\n");
			   else printf("No\n");
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}