提交记录 22061


用户 题目 状态 得分 用时 内存 语言 代码长度
LEE114514 noip17b. 【NOIP2017】时间复杂度 Accepted 100 53.1 us 48 KB C++ 2.13 KB
提交时间 评测时间
2024-07-30 19:54:34 2024-07-30 19:54:37
#include <bits/stdc++.h>
using namespace std;
int T;
void work();
int main(){
	// 先交一发
	// freopen("complexity.in","r",stdin);
	// freopen("complexity.out","w",stdout);
	scanf("%d",&T);
	while(T--) work();
}
int l,d,w,n,pos,ans;
char str[100];
bool vis[105];
bool CE;
int cur;
char s[105][100];
int len[105],presum;
int solve(int &p){
	char x=s[p][3];
	if(vis[x-'a']){
		CE=1;
		return 0;
	}
	vis[x-'a']=1;
	int flag=1;
	if(s[p][5]=='n'){
		flag=0;
		char* i=s[p]+5;
		for(char* i=s[p]+5;isdigit(*i);++i);
		++i;
		if(*i==' ') ++i;
		if(*i!='n') flag=-1;
	}else{
		int l=0,r=0;
		char* i=s[p]+5;
		for(;isdigit(*i);++i) l=l*10+((*i)^48);
		++i;
		if(*i=='n') flag=1;
		else{
			for(;isdigit(*i);++i) r=r*10+((*i)^48);
			if(l<=r) flag=0;
			else flag=-1;
		}
	}
	int tmpans=0;
	// while(presum>nowtop){
	while(s[p+1][1]=='F') tmpans=max(solve(++p),tmpans);
	++p;	
	// }
	vis[x-'a']=0;
	if(flag==1) ++tmpans;
	else if(flag==-1) tmpans=0;
	// cerr<<p<<' '<<tmpans<<'\n';
	return tmpans;
}
void mygetline(char* p){
	char ch=getchar();
	while(ch!='\n'&&ch!=EOF) *p=ch,++p,ch=getchar();
}
void work(){
	memset(vis,0,sizeof vis);
	vis['n'-'a']=1;
	scanf("%d%s ",&l,str+1);
	n=strlen(str+1);
	pos=-1;
	for(int i=1;i<=n;++i){
		if(str[i]=='^'){
			pos=i;
			break;
		}
	}
	w=0;
	if(pos==-1) w=0;
	else for(int i=pos+1;isdigit(str[i]);++i) w=w*10+(str[i]^48);
	CE=0;
	for(int i=1;i<=l;++i) mygetline(s[i]+1),len[i]=strlen(s[i]+1);
	presum=0;
	for(int i=1;i<=l;++i){
		// cerr<<(s[i]+1)<<'\n';
		if(s[i][1]=='F') ++presum;
		else --presum;
		if(presum<0){
			puts("ERR");
			return;
		} 
	}//F-E 匹配CE
	if(presum){
		puts("ERR");
		return;
	}
	cur=1;
	ans=0;
	while(cur<=l){
		ans=max(solve(cur),ans);
		++cur;
		if(CE) break;
	}
	if(CE) puts("ERR");
	else puts(ans==w?"Yes":"No");
	// cerr<<ans<<' '<<w<<'\n';
}
/*
42 O(n^4)
F a 38 n
	F b 7 n
		F c n n
			F d 79 n
				F e 20 n
					F f 99 7
						F g 68 n
							F h 74 n
								F i 24 n
								E
							E
						E
					E
				E
			E
		E
	E
E
F a 10 n
	F b 65 n
		F c 45 91
			F d n 7
				F e 44 n
				E
			E
		E
	E
E
F a 75 n
	F b 55 n
		F c 82 39
			F d 59 n
				F e 38 n
					F f 36 50
						F g 40 n
						E
					E
				E
			E
		E
	E
E
*/

CompilationN/AN/ACompile OKScore: N/A

Testcase #140.3 us40 KBAcceptedScore: 10

Testcase #236.97 us40 KBAcceptedScore: 10

Testcase #339.15 us40 KBAcceptedScore: 10

Testcase #441.68 us44 KBAcceptedScore: 10

Testcase #543.05 us44 KBAcceptedScore: 10

Testcase #640.66 us44 KBAcceptedScore: 10

Testcase #743.54 us48 KBAcceptedScore: 10

Testcase #847.2 us48 KBAcceptedScore: 10

Testcase #946 us48 KBAcceptedScore: 10

Testcase #1053.1 us48 KBAcceptedScore: 10


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:10:04 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠