#P4487. Kakuro XOR Puzzle
Kakuro XOR Puzzle
Kakuro XOR Puzzle
This puzzle is a variant of Kakuro where each white cell (denoted by a '?' in the input) must be filled with a unique positive integer (not exceeding \(2^{60}-1\)). In cells containing a clue (in the format a\b
), the number in the top‐right (the value a
) is equal to the XOR of all consecutive white cells immediately to its right, and the number in the bottom‐left (the value b
) is equal to the XOR of all consecutive white cells immediately below it. If there is no white cell in that direction, consider the XOR as 0.
Your task is to fill in all the white cells with distinct positive integers so that all clues are satisfied.
Input Format:
The first line contains two integers R and C, the number of rows and columns in the grid.
Each of the next R lines contains C tokens separated by spaces. A token is either a clue cell in the format a\b
(with no extra spaces) or a white cell represented by a '?' character.
Output Format:
Output the grid after filling in all white cells. For clue cells, output them unchanged; for white cells, output the assigned positive integer. Each row should be printed on a separate line with tokens separated by a single space.
inputFormat
The input begins with a line containing two integers R and C (1 ≤ R, C ≤ small value). It is followed by R lines, each of which contains C tokens separated by a space. A token is either:
- A clue cell in the format
a\b
(without quotes) wherea
andb
are nonnegative integers. The numbera
is the target XOR on the horizontal (right) adjacent white cells, andb
is the target XOR on the vertical (down) adjacent white cells. - A white cell represented by a single character
?
.
outputFormat
Output the completed grid of R rows and C columns. For each cell, if it is a clue cell, output it exactly as in the input; if it is a white cell, output the positive integer assigned to that cell. Separate tokens with a single space, and each row should be on its own line.
sample
3 3
0\0 0\0 0\0
3\0 ? ?
5\0 ? ?
0\0 0\0 0\0
3\0 1 2
5\0 3 6
</p>