No.3191 Operation Puzzle
タグ : / 解いたユーザー数 112
作問者 :
noya2
Problem Statement
You are given a sequence of positive integers $A=(A_1,A_2,\dots ,A_N)$ of length $N$ and a positive integer $X$. Here, each of the values $A_1,A_2,\dots, A_N,X$ is one of $1,2,3,4$.
A table $f$ of positive integers with $4$ rows and $4$ columns is called a nice table if it satisfies the following conditions. Here, the element in the $i$-th row from the top and the $j$-th column from the left of the table is denoted by $f(i,j)$.
- All $16$ elements contained in the table are one of $1,2,3,4$.
- $f(f(\dots f(f(A_1,A_2),A_3),\dots),A_N)=X$ holds.
Determine whether a nice table exists, and if it does, output $1$ such table.
Constraints
- All inputs are integers.
- $2\le N\le 100$
- Each of $A_1,A_2,\dots, A_N,X$ is one of $1,2,3,4$.
Input
$N$ $A_1$ $A_2$ $\dots A_N$ $X$
Output
On the first line, output Yes if a nice table exists, and No otherwise.
If a nice table exists, output $4$ more lines. On the line for each $i=1,2,3,4$ among them, output $f(i,1),f(i,2),f(i,3),f(i,4)$ separated by spaces.
Sample
Sample 1
Input
4 1 2 3 4 3
Output
Yes 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3
This satisfies $f(f(f(1,2),3),4)=f(f(2,3),4)=f(4,4)=3$.
Note that, when $f$ is regarded as a binary operation, it is left-associative.
Sample 2
Input
2 4 3 1
Output
Yes 3 3 1 3 3 1 1 3 3 3 1 3 3 1 1 1
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。