[Codeforces] Round #528 div1C div2E

https://codeforces.com/contest/1086/problem/C

贪心匹配,只有三种状态:压上界,压下界,不压界(出解)

#include
using namespace std;
#define N 1000005

int n,k;
char a[N],b[N],c[N];
int go[30];
bool use[30];


inline void op()
{
	for (int i=0;i=b[i] && !flag) || go[c[i]]a[i] && (go[c[i]]a[i]) flag=1;
	}
	puts("YES");
	op();
	return;
	up:;
	memset(go,-1,sizeof(go));
	memset(use,0,sizeof(use));
	flag=0;
	for (int i=0;ib[i])
			{
				goto fail;
			}
			if (go[c[i]]a[i] || flag))
			{
				puts("YES");
				op();
				return;
			}	
		}
		else
		{
			for (int j=b[i]-1;j>(flag?-1:a[i]);j--) if (!use[j])
			{
				use[j]=1;
				go[c[i]]=j;
				puts("YES"); 
				op();
				return;
			}
			if (use[b[i]]) goto fail;
			go[c[i]]=b[i];
			use[b[i]]=1;
		}
		if (b[i]>a[i]) flag=1;
	}	
	puts("YES");
	op();
	return;
	fail:puts("NO");
}

 
int main()
{
	int T;
	scanf("%d",&T);
	while (T--) solve();
}

你可能感兴趣的:(CodeForces,greedy)