Bingo
Time limit1sMemory limit1024 MB
Given n and k, decide whether exactly k filled cells in an n x n grid can avoid completing any full row, column, or diagonal, and print such a grid.
- Level
Medium5 of 10
- Topics
- Implementation, Greedy, Math, Brute force
- Solved
- No attempts yet
Problem
Bingo is a game played on a square grid. Each player gets an grid and writes a distinct number in each cell. The host then draws a random number, and each player looks for that number on their grid and fills the corresponding cell if the number is present. This repeats until someone gets filled cells on a single line, which we call a bingo line.
There are possible bingo lines: horizontal lines, vertical lines, and diagonal lines.
--- ... ... |.. .|. ..| \.. ../
... --- ... |.. .|. ..| .\. ./.
... ... --- |.. .|. ..| ..\ /..
For example, the following grid has four bingo lines: two horizontal lines, one vertical line, and one diagonal line.
#..#.
#####
..###
#####
..###
When exactly is a bingo line formed? This is completely random. If you are lucky you can complete a line quite early, and on the other hand you can fill most of the grid without making any bingo line. In this problem we look at the unlucky case of filling cells without making any bingo line.
Given two integers and , determine whether it is possible to fill exactly cells of an grid without making any bingo line. If it is possible, show one way to do it.
Input
The first and only line of input contains two integers, and .
Output
On the first line, output YES if it is possible to fill exactly cells of an grid without making any bingo line. Otherwise, output NO.
If the answer is YES, output each row of the grid starting from the next line. Each row is a string of characters. The -th character is # (ASCII 35) if the -th cell of the row is filled, and . (ASCII 46) if it is not. Exactly cells must be filled, and there must be no bingo line.
If there are multiple ways to fill the grid, output any one of them.
Constraints
Hint
The second example is valid only for subtasks 2 and 3.