#P9687. Unique Map
Unique Map
Unique Map
You are given a grid map of length (n) and width 1 (i.e. a string of length (n)), where each cell must be painted either white (denoted by 0) or black (denoted by 1). In addition, for every white cell that is not at one of the two endpoints (i.e. for every white cell at index (i) with (2 \le i \le n-1)), the following condition must be satisfied:
[ \text{value} = ; (\text{left neighbor is black}) + (\text{right neighbor is black}) = p, ]
where the expression “left neighbor is black” is interpreted as (1) if the cell immediately to the left is black (1) and (0) otherwise, and similarly for the right neighbor. Note that this condition imposes feasibility constraints:
- When (p=0), for an interior white cell, both its left and right neighbors must be white, and hence its left neighbor must not be black.
- When (p=1), if the left neighbor is white then the right neighbor must be black, whereas if the left neighbor is black then the right neighbor must be white.
- When (p=2), for an interior white cell, both its left and right neighbors must be black (so its left neighbor must be black).
Your task is to output the lexicographically smallest (with '0' < '1') valid map (a binary string of length (n)) that satisfies the above condition for every interior white cell. Endpoints do not need to satisfy any condition.
inputFormat
The input consists of a single line containing two integers (n) and (p) (with (1 \le n \le 50) for instance and (p \in {0,1,2})), where (n) is the length of the map and (p) is the required number in the condition.
outputFormat
Output a binary string of length (n) representing the lexicographically smallest valid map that satisfies the condition for every white cell (with value 0) not on the endpoints.
sample
3 1
001