#P15042. [UOI 2022 II Stage] 双色图形

    ID: 16970 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2022Special Judge构造UOI(乌克兰)

[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 bb black cells and ww 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 ww and bb (0≤w,b≤1000 \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-1.

Otherwise, output two integers nn and mm (1≤n,m≤2501 \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 nn lines, each containing mm 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 ww white cells and bb 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 w=bw = b will receive at least 3030 points.

A solution that works correctly for the case max⁡(w,b)≤2⋅min⁡(w,b)\max(w, b) \le 2 \cdot \min(w, b) will receive at least 6060 points.

Translated by DeepSeek V3.

Translated by ChatGPT 5