No.3649 Top View of Jenga
タグ : / 解いたユーザー数 77
作問者 :
とある理系大学生の日常
Problem Statement
You are building a tower using $N$ wooden blocks.
Viewed from directly above, the tower is divided into a grid of $3$ rows and $3$ columns, for a total of $9$ cells. The cell in the $i$-th row from the top and the $j$-th column from the left of this grid is denoted by $(i, j)$.
Each block has a size of $3$ cells by $1$ cell and can be rotated freely. Perform the following operations until you run out of blocks.
- The tower is built by stacking blocks. Level $h = 1, 2, \dots$ is stacked as follows.
When $h$ is odd
- For $j = 1, 2, 3$ in this order, stack $1$ block so that it covers the $3$ cells $ ( 1 , j ) , ( 2 , j ) , ( 3 , j ) $.
If you run out of blocks along the way, the operation ends at that point. - Once all $3$ blocks have been stacked, move on to level $h+1$.
- For $j = 1, 2, 3$ in this order, stack $1$ block so that it covers the $3$ cells $ ( 1 , j ) , ( 2 , j ) , ( 3 , j ) $.
When $h$ is even
- For $i = 1, 2, 3$ in this order, stack $1$ block so that it covers the $3$ cells $ ( i , 1 ) , ( i , 2 ) , ( i , 3 ) $.
If you run out of blocks along the way, the operation ends at that point. - Once all $3$ blocks have been stacked, move on to level $h+1$.
- For $i = 1, 2, 3$ in this order, stack $1$ block so that it covers the $3$ cells $ ( i , 1 ) , ( i , 2 ) , ( i , 3 ) $.
After all $N$ blocks have been stacked, find, for each of the $9$ cells seen from directly above, how many blocks are stacked on it.
Constraints
- $1 \le N \le 10^{12}$
- $N$ is an integer.
Input
The input is given from standard input in the following format.
$N$
Output
The output consists of $3$ lines. On the $i$-th line, print the numbers of blocks stacked on cells $(i, 1), (i, 2), (i, 3)$, separated by spaces.
Print a newline at the end.
Note that the answer may not fit in a $32$ bit integer type (such as int).
Sample
Sample 1
Input
1
Output
1 0 0 1 0 0 1 0 0
Block number $1$ is block number $1$ of an odd-numbered level, so it is placed vertically in the left column. Therefore, the $3$ cells of the leftmost column each have $1$ block placed on them.
Sample 2
Input
4
Output
2 2 2 1 1 1 1 1 1
Sample 3
Input
11
Output
4 4 4 4 4 4 3 3 3
Sample 4
Input
1000000000000
Output
333333333334 333333333334 333333333334 333333333333 333333333333 333333333333 333333333333 333333333333 333333333333
Note that the input and output may not fit in a $32$ bit integer type (such as int).
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。