#P6972. Freckle Picture Translation
Freckle Picture Translation
Freckle Picture Translation
Kevin and Kimberly each have drawn a freckle picture on a rectangular sheet of pixels. In each picture every cell either contains a freckle (represented by 1) or no freckle (represented by 0). They propose that the child’s freckle picture is produced by taking Kevin's fixed picture and overlaying Kimberly's picture after it is translated by a vector (dx, dy). In the resulting picture, a cell contains a freckle if and only if exactly one of the two parents had a freckle in that cell.
Formally, if we denote Kevin's picture by K, Kimberly's picture by M, and the resulting child picture by C, then for each cell (i, j) (0-indexed) the following holds:
$$C[i,j] = K[i,j] \oplus \begin{cases} M[i-dy,j-dx] & \text{if } 0 \le i-dy < r \text{ and } 0 \le j-dx < c,\\ 0 & \text{otherwise.} \end{cases} $$Here, \(\oplus\) denotes the exclusive or (XOR) operation. Given the three pictures, your task is to determine a translation vector (dx, dy) for Kimberly's picture so that the XOR of the two (with Kimberly's shifted) equals the given target child picture. If multiple translations are possible, output any one; if no such translation exists, output No solution
.
inputFormat
The first line contains two integers r
and c
(the number of rows and columns respectively).
The next r
lines each contain a string of length c
representing Kevin's picture. Each character is either '0' or '1'.
The following r
lines describe Kimberly's picture in the same format.
The next r
lines describe the target child picture in the same format.
Note: Rows and columns are 0-indexed. The translation (dx, dy) means that every cell M[i][j]
of Kimberly's picture is moved to cell [i+dy][j+dx]
(or equivalently, for a fixed cell in the child picture, the corresponding cell in Kimberly's picture is [i-dy][j-dx]
).
outputFormat
If a valid translation exists, output two space-separated integers dx
and dy
representing the horizontal and vertical shifts respectively. Otherwise, output No solution
.
sample
3 3
010
101
010
001
110
001
010
110
010
1 0