| 2026 Fall UT CS104c Midterm #2 |
|---|
| Finished |
A UTPC Code is similar to a QR code: it is a square bitmap of white and black pixels that encodes data. Not any bitmap is a valid UTPC Code, though. Valid codes must satisfy the following parity constraint: in any $$$2\times 2$$$ contiguous block of pixels, the number of black pixels in the block must be even. In other words, the following $$$2\times 2$$$ blocks cannot appear anywhere inside a valid UTPC Code:
WB BW BB BB BW WB WW WW
BB BB WB BW WW WW BW WB
where W and B represent white and black pixels, respectively.
You are given an $$$N \times N$$$ grid with some pixel colors already filled in. Is it possible to complete the rest of the UTPC Code in a way that satisfies the parity constraint?
First line of input contains a single integer $$$N$$$ $$$(1 \leq N \leq 10)$$$: the size of the grid. Then follow $$$N$$$ lines of exactly $$$N$$$ characters each. Each character will be one of W, B, or ., representing a white or black pixel already given at that location in the grid, or a blank spot that you need to fill in, respectively.
Print POSSIBLE if it is possible to fill in all remaining . cells with a black or white pixel in a way that satisfies the UTPC parity constraint, and IMPOSSIBLE otherwise.
3W.WBBB...
POSSIBLE
5WWBWBW....B...B..W...W...
IMPOSSIBLE
In the first sample, one valid completion is
WWW
BBB
WWW
In the second sample, it is impossible to fill in the unknown pixels so that the completed grid satisfies the parity rule.
| Name |
|---|


