問題一覧 > 通常問題

No.3191 Operation Puzzle

レベル : / AI推定難易度 : 151 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 112
作問者 : noya2
お気に入りにしたユーザー ProblemId : 12426 / 自分の提出
問題文最終更新日: 2025-06-27 21:18:02
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 472 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。