#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 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 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, and () 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, and , respectively (). and only contain the digits and .
represents the initial state of the coins: if the head of the -th coin faces up, then the -th character of is ; otherwise (i.e. the head of -th coin faces down), the -th character of is . represents the desired final state of the coins in the same way as .
Output Format
If it is possible for Eva to reach the state represented by from the state represented by in finite steps, output "Yes"; otherwise, output "No" (without the quotes).
6 2
000000
101101
Yes
8 3
10101010
01010101
No