Back to problems Sign in to unlock
Codeforces
Easy
Matrices
Strings
DZY Loves Chessboard
Fill the empty cells of a chessboard-like grid so adjacent cells alternate between two characters while preserving the blocked cells.
Acceptance 0%
Problem Statement
You are given an board made of characters . and -.
Replace every . with either B or W so that:
- no two horizontally or vertically adjacent non-
-cells have the same character, - cells marked
-must stay unchanged.
The resulting board should form a chessboard-style alternating pattern on all non-blocked cells. Output any valid board.
Input Format
- The first line contains two integers and .
- The next lines each contain a string of length describing the board.
- Each cell is one of
.or-.
Output Format
Print lines describing a valid board after replacing all . cells with B or W.
Constraints
- The board dimensions are small enough for direct construction.
- A valid alternating coloring always exists for the given board.
Examples
Sample cases returned by the problem API.
Example 1
Input
3 4 .... .-.. ....
Output
BWBW W-BW BWBW
Explanation
Fill each . using a checkerboard coloring. The - cell stays unchanged.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.