No.2339 Factorial Paths
Problem Statement
You are given a positive integer $N$. Freely choose positive integers $H, W$ and construct a grid with $H$ rows and $W$ columns that satisfies all of the following conditions.
Here, the cell in the $i$-th row from the top ($1 \leq i \leq H$) and the $j$-th column from the left ($1 \leq j \leq W$) is denoted by cell $(i,j)$.
- $1 \leq H \leq 2\,000$
- $1 \leq W \leq 2\,000$
- Each cell is painted white or black.
- There are exactly $N!$ paths from cell $(1,1)$ to cell $(H,W)$ that repeatedly move $1$ cell to the right or down, passing only through cells painted white.
- More formally, there are $N!$ sequences of cells $(x_1, y_1), (x_2, y_2), \dots, (x_{H+W-1}, y_{H+W-1})$ that satisfy all of the following conditions.
- $(x_1,y_1)=(1,1)$
- $(x_{H+W-1},y_{H+W-1})=(H,W)$
- For each $i \ (1 \leq i \leq H + W - 1)$, cell $(x_i, y_i)$ is painted white.
- For each $i \ (1 \leq i \leq H + W - 2)$, $(x_{i+1}, y_{i+1})$ is either $(x_i+1, y_i)$ or $(x_i,y_i+1)$.
- Here, $2$ sequences of cells are considered different if there exists some $i \ (1 \leq i \leq H+W-1)$ for which $(x_i, y_i)$ differs.
Input
The input is given from standard input in the following format.
$N$
Output
Print to standard output in the following format.
$H$ $W$
$S_{1,1}S_{1,2} \cdots S_{1,W}$
$S_{2,1}S_{2,2} \cdots S_{2,W}$
$\vdots$
$S_{H,1}S_{H,2} \cdots S_{H,W}$
Here, $S_{i,j}$ ($1 \leq i \leq H, 1 \leq j \leq W$) is . if cell $(i,j)$ is painted white, and # if it is painted black.
Print a newline at the end.
Constraints
The input satisfies the following constraints.
- $1 \leq N \leq 400$
- $N$ is an integer.
Sample
Sample 1
Input
3
Output
3 3 ... ... ...
There are exactly $3!=6$ paths.
Sample 2
Input
5
Output
6 6 ....#. ...... ..#... ...... #..... ......
There are exactly $5!=120$ paths.
Sample 3
Input
1
Output
3 4 ..## #..# ##..
You do not need to minimize $H$ and $W$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
SSRS
ぷら
Nachia