P15042 [UOI 2022 II Stage] Two-Color Shape

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 $b$ black cells and $w$ white cells. The shape does not need to be fully filled, but it must be connected. :::align{center} ![](https://cdn.luogu.com.cn/upload/image_hosting/p1gclb0x.png) 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} ![](https://cdn.luogu.com.cn/upload/image_hosting/txk6wn82.png) 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 $w$ and $b$ ($0 \leq w, b \leq 100$), representing the numbers of white cells and black cells, respectively.

Output Format

If no solution exists, output a single number $-1$. Otherwise, output two integers $n$ and $m$ ($1 \leq n, m \leq 250$) 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 $n$ lines, each containing $m$ 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 $w$ white cells and $b$ 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).

Explanation/Hint

### Scoring A solution that works correctly for the case $w = b$ will receive at least $30$ points. A solution that works correctly for the case $\max(w, b) \le 2 \cdot \min(w, b)$ will receive at least $60$ points. Translated by DeepSeek V3. Translated by ChatGPT 5