Paint By Numbers is a well-known puzzle game. We consider a simple one-dimensional version of this puzzle. In this puzzle, the player is given a row of X
to denote black cells and _
to denote white cells.
The player is given a sequence _XXX__XXXX
. Note that XXXX_XXX__
does not satisfy the clues because the blocks of black cells are not in the correct order. Also, __XXXXXXX_
does not satisfy the clues because there is a single block of black cells, not two separate blocks.
You are given a partially solved Paint By Numbers puzzle. That is, you know
Specifically, a valid solution is one that satisfies the clues, and also agrees with the colours of the known cells. Your program should find cells that are painted black in every valid solution, and cells that are painted white in every valid solution.
You may assume that the input is such that there is at least one valid solution.
Input Specification
Line
X
, if cell must be black,_
, if cell must be white,.
, if there is no information about cell .
Line
Output Specification
Your program should output a string of length
X
, if cell is black in every valid solution,_
, if cell is white in every valid solution,?
, otherwise (i.e., if there exist two valid solutions such that cell is black in one of them and white in the other one).
Sample Input 1
..........
2 3 4
Sample Output 1
??X???XX??
Explanation for Sample Output 1
These are all possible valid solutions of the puzzle:
XXX_XXXX__
,XXX__XXXX_
,XXX___XXXX
,_XXX_XXXX_
,_XXX__XXXX
,__XXX_XXXX
.
One can observe that the cells with (0-based) indices 2, 6, and 7 are black in each valid solution. Each of the other cells can be, but does not have to be black. Hence, the correct answer is ??X???XX??
.
Sample Input 2
........
2 3 4
Sample Output 2
XXX_XXXX
Explanation for Sample Output 2
In this example the entire solution is uniquely determined and the correct answer is XXX_XXXX
.
Sample Input 3
..._._....
1 3
Sample Output 3
???___????
Explanation for Sample Output 3
In this example we can deduce that cell 4 must be white as well — there is no way to fit three consecutive black cells between the white cells at indices 3 and 5. Hence, the correct answer is ???___????
.
Sample Input 4
.X........
1 3
Sample Output 4
?XX?______
Explanation for Sample Output 4
There are only two valid solutions that match the above description:
XXX_______
,_XXX______
.
Thus, the correct answer is ?XX?______
.
Subtasks
In all subtasks
- (7 points)
, , contains only.
(empty puzzle), - (3 points)
, contains only.
, - (22 points)
, contains only.
, - (27 points)
, contains only.
and_
(information about white cells), - (21 points)
, - (10 points)
, , - (10 points)
, .
Comments