#P17322. [ICPC 2018 Nanjing R] Eva and Euro coins

[ICPC 2018 Nanjing R] Eva and Euro coins

Problem Description

Eva is fond of collecting coins. Whenever she visits a different country, she always picks up as many local coins as she can. As you know, Eva also likes to go trips to Europe; thus she has collected a large amount of Euro coins because so many countries in Europe use them.

Eva has nn Euro coins in total. She places all her coins on a desk in a row and plays a game with the coins. In one step Eva can choose exactly kk consecutive coins and flips them at the same time, provided that all heads of these coins face up or all heads of these coins face down. She wonders that, in finite steps, what states of the coins can be reached from the original state.

Input Format

The first line contains two integers, nn and kk (1≤k≤n≤1061 \le k \le n \le 10^6) —\text{---}the number of Euro coins Eva owns and the number of consecutive coins Eva can flip in one step.

The next two lines contain two strings, ss and tt, respectively (∣s∣=∣t∣=n|s| = |t| = n). ss and tt only contain the digits 00 and 11.

ss represents the initial state of the nn coins: if the head of the ii-th coin faces up, then the ii-th character of ss is 11; otherwise (i.e. the head of ii-th coin faces down), the ii-th character of ss is 00. tt represents the desired final state of the nn coins in the same way as ss.

Output Format

If it is possible for Eva to reach the state represented by tt from the state represented by ss in finite steps, output "Yes"; otherwise, output "No" (without the quotes).

6 2
000000
101101
Yes
8 3
10101010
01010101
No