E - Christmas Wreath 解説 /

実行時間制限: 3 sec / メモリ制限: 1024 MB

配点 : 600

問題文

高橋君は、N 個のボールと \frac{N(N-1)}{2} 個のロープからなるクリスマス飾りを持っています。ボールには 1 から N までの番号が付けられており、どの 2 つの相異なるボールについても、ちょうど 1 つのロープで結ばれています。

彼は、それぞれのロープを赤・青・白のいずれかの色で点灯させることにしました。

見栄えを良くするため、以下の条件をすべて満たすようにしたいです。

条件1 赤・青・白で点灯されているロープの数は、すべて同数である。

条件2 整数 a, b, c (1 \leq a < b < c \leq N) であって、以下の 3 つのロープの色がすべて異なるものは存在しない。

  • ボール ab を結ぶロープ
  • ボール bc を結ぶロープ
  • ボール ac を結ぶロープ

条件を満たす点灯の方法を 1 つ構成してください。このような方法が存在しない場合、その旨を出力してください。

制約

  • 3 \leq N \leq 50
  • N は整数

入力

入力は以下の形式で標準入力から与えられます。

N

出力

条件を満たす点灯の方法が存在しない場合は、No と出力してください。

存在する場合は、以下の形式で出力してください。

Yes
c_{1,2}c_{1,3}c_{1,4}\ldotsc_{1,N}
c_{2,3}c_{2,4}\ldotsc_{2,N}
 :
c_{N-1,N}

ただし、文字 c_{i, j} (1 \leq i < j \leq N) は以下の通りにしてください。

  • ボール ij を結ぶロープを赤にするとき:c_{i, j} = R
  • ボール ij を結ぶロープを青にするとき:c_{i, j} = B
  • ボール ij を結ぶロープを白にするとき:c_{i, j} = W

入力例 1

4

出力例 1

No

N=4 では、条件を満たす点灯の方法が存在しないため、No と出力すれば正解となります。

Yes のときの出力の一例も以下に示しておきますが、このケースでは不正解となります。これは、条件2(a, b, c) = (1, 2, 3) を選ぶと、ボール a, b を結ぶロープは赤、ボール b, c を結ぶロープは白、ボール a, c を結ぶロープは青と、すべて異なるからです。

Yes
RBW
WB
R

Score : 600 points

Problem Statement

Takahashi has Christmas decoration consisting of N balls and \frac{N(N-1)}{2} ropes. The balls are numbered 1 to N, and for any two different balls, there is exactly one rope that connects them.

He decides to light up each rope in red, blue, or white.

For better appearance, he wants to satisfy all of the following conditions.

Condition 1 the numbers of ropes lighted in red, blue, and white are all equal.

Condition 2 there is no triple of integers a, b, c (1 \leq a < b < c \leq N) such that all of the following three ropes have different colors:

  • the rope connecting a and b,
  • the rope connecting b and c,
  • the rope connecting a and c.

Create a way to light up the ropes to satisfy the conditions. If there is no such way, report so.

Constraints

  • 3 \leq N \leq 50
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If there is no way to light up the ropes to satisfy the conditions, print No.

If such a way exists, print it in the following format:

Yes
c_{1,2}c_{1,3}c_{1,4}\ldotsc_{1,N}
c_{2,3}c_{2,4}\ldotsc_{2,N}
 :
c_{N-1,N}

Here, the character c_{i, j} (1 \leq i < j \leq N) should be the following:

  • c_{i, j} = R when lighting up the rope connecting Balls i and j red,
  • c_{i, j} = B when lighting up the rope connecting Balls i and j blue,
  • c_{i, j} = W when lighting up the rope connecting Balls i and j white.

Sample Input 1

4

Sample Output 1

No

For N=4, there is no way to light up the ropes to satisfy the conditions, so the output No is correct.

Below is an example of an output in the Yes case, which is incorrect in this case. This is because, for (a, b, c) = (1, 2, 3) in Condition 2, the rope connecting a, b is red, the rope connecting b, c is white, and the rope connecting a, c is blue, all of which have different colors.

Yes
RBW
WB
R