#P15042. [UOI 2022 II Stage] 双色图形
[UOI 2022 II Stage] 双色图形
Problem Description
For her birthday, Ksonia received an infinite chessboard, where each cell is colored either black or white. She wants to cut out a connected shape from it, but the shape must contain exactly black cells and white cells. The shape does not need to be fully filled, but it must be connected.
:::align{center}

An example of a valid shape. The unfilled cells in the middle do not matter; the key is that the shape must be connected. This shape has four white cells and four black cells. :::
:::align{center}

An example of an invalid shape because it is not connected. :::
Please help Ksonia find any such shape, or state that it does not exist.
Input Format
The first line contains two integers and (), representing the numbers of white cells and black cells, respectively.
Output Format
If no solution exists, output a single number .
Otherwise, output two integers and () in the first line, the size of the rectangular region containing the required shape. It can be proven that if a solution exists, then there is a solution that satisfies this limit.
Then output lines, each containing characters, describing the shape. If a cell in the rectangle is empty, output .; if it is a white cell, output W; if it is a black cell, output B.
The shape obtained from this rectangle must be connected, contain exactly white cells and black cells, and be colored in a chessboard pattern (a white cell can only be adjacent to an empty cell or a black cell, and a black cell can only be adjacent to an empty cell or a white cell).
2 2
3 5
.....
BWBW.
.....
3 4
3 7
.......
BWBWBWB
.......
3 100
-1
Hint
Scoring
A solution that works correctly for the case will receive at least points.
A solution that works correctly for the case will receive at least points.
Translated by DeepSeek V3.
Translated by ChatGPT 5