gym 101981E 2018ICPC南京区域赛 Problem E. Eva and Euro coins

k个相同字符相邻是没有意义的,可以消去
具体解释:
k个1可以变成0
k个0可以把其后方紧邻的1搬到前面

贪心处理两个串,判断是否相等

#include
#define N 1000005

int stk[N][2],top,n,k;
char a[N],b[N];

inline void solve(char s[])
{
	stk[top=0][0]=-1;
	for (int i=1;i<=n;i++)
	{
		stk[++top][0]=s[i]-'0';
		stk[top][1]=stk[top-1][0]==s[i]-'0'?stk[top-1][1]+1:1;
		if (stk[top][1]==k) top-=k; 
	}
	for (int i=1;i<=n;i++) s[i]=i<=top?stk[i][0]+'0':'0';
}

int main()
{
	scanf("%d%d",&n,&k);
	scanf("%s%s",a+1,b+1);
	solve(a);
	solve(b);
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) {puts("No");return 0;}
	puts("Yes");
}

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