#P7141. [THUPC 2021 初赛] 棋盘
[THUPC 2021 初赛] 棋盘
Description
There is a chessboard with rows and columns, with a total of cells. Please place pieces in the cells (each cell can contain at most one piece) such that for all , the -th column contains exactly pieces. In addition, any two pieces on the chessboard must not be edge-adjacent.
Determine whether a valid arrangement exists. If it exists, output any valid arrangement.
Input Format
The first line contains two positive integers , and it is guaranteed that .
The second line contains non-negative integers , and it is guaranteed that .
Output Format
If there is no solution, output a string No.
If there is a solution, output a string Yes on the first line, then output lines, each containing a string of length representing the chessboard arrangement you construct. Here, 0 means an empty cell, and 1 means a cell with a piece.
3 4
2 1 2 1
Yes
1010
0101
1010
3 4
2 3 3 3
No
Hint
[Source]
From the preliminary round of the 2021 Tsinghua University Student Algorithm Competition and Collegiate Invitational Contest (THUPC2021).
Resources such as solutions can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5
京公网安备 11011102002149号