P17322 [ICPC 2018 Nanjing R] Eva and Euro coins
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 $n$ 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 $k$ 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, $n$ and $k$ ($1 \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, $s$ and $t$, respectively ($|s| = |t| = n$). $s$ and $t$ only contain the digits $0$ and $1$.
$s$ represents the initial state of the $n$ coins: if the head of the $i$-th coin faces up, then the $i$-th character of $s$ is $1$; otherwise (i.e. the head of $i$-th coin faces down), the $i$-th character of $s$ is $0$. $t$ represents the desired final state of the $n$ coins in the same way as $s$.
Output Format
If it is possible for Eva to reach the state represented by $t$ from the state represented by $s$ in finite steps, output "Yes"; otherwise, output "No" (without the quotes).