A - Copy-Paste Painting (A)

Time Limit: 2 sec / Memory Limit: 1024 MiB

ストーリー

高橋画伯は、画像編集ソフトを駆使して新作アートの制作に取り組んでいる。 作品作りでは、複数のレイヤーを使い分けながら、少しずつ絵を描き足したり、別のレイヤーの内容を回転して重ねたり、不要になったレイヤーを消したりできる。 目標となる画像をできるだけ少ない手数で完成させる手順を求めてほしい。

問題文

N\times N のピクセルからなるレイヤーが K 枚ある。 各レイヤーには 0,\cdots,K-1 の番号が付けられている。 左上のピクセルの座標を (0,0) とし、そこから下に i ピクセル、右に j ピクセル進んだ先のピクセルの座標を (i,j) とする。

使用できる色は C 色あり、各色には 1,\cdots,C の番号が付けられている。 レイヤー k のピクセル (i,j) の色を c(k,i,j) で表すことにする。 c(k,i,j)=0 は、そのピクセルが透明であることを表す。

目標画像は、各ピクセルの色 g_{i,j} によって与えられる。 すべての (i,j) について c(0,i,j)=g_{i,j} が成り立つとき、目標画像が完成しているものとする。 他のレイヤーの状態は問わない。

初期状態では、すべてのレイヤーは透明であり、すべての k,i,j について c(k,i,j)=0 である。 以下の操作を高々 N^2 回繰り返すことで、目標画像を完成させよ。

  • \mathrm{paint}(k,i,j,x): レイヤー k\in\{0,\cdots,K-1\}、ピクセル (i,j)、色 x\in\{0,\cdots,C\} を指定し、c(k,i,j)=x に変更する。x=0 を指定した場合、そのピクセルは透明に戻る。
  • \mathrm{copy}(k,h,r,\Delta i,\Delta j): レイヤー k,h\in\{0,\cdots,K-1\}、整数 r\in\{0,\cdots,3\}\Delta i\in\{-N+1,\cdots,N-1\}\Delta j\in\{-N+1,\cdots,N-1\} を指定する。レイヤー h を時計回りに 90 度回転する操作を r 回行って得られるレイヤーを h' とする。ただし、レイヤー h 自体は変更されない。h' の左上のピクセルがレイヤー k のピクセル (\Delta i,\Delta j) に対応するように配置し、重ねる。その後、h' で透明でないピクセルをレイヤー k に上書きする。すなわち、c(h',i,j)\neq 0 であるすべての (i,j) に対し、c(k,\Delta i+i,\Delta j+j)=c(h',i,j) と更新する。この操作によってレイヤー k の範囲外のピクセルが塗られる場合、WA と判定される。k=h であってもよい。
  • \mathrm{clear}(k): レイヤー k のすべてのピクセルを透明にする。

得点

操作回数を T とする。 目標画像において非透明なピクセル数、すなわち g_{i,j}\neq 0 を満たす (i,j) の個数を U とする。 このとき、以下の得点が得られる。

\[ \mathrm{round}\left(10^6\times \left(1+\log_2 \frac{U}{T}\right)\right) \]

入力生成方法の違いにより、問題は A・B の 2 問 に分かれている。 それぞれ 150 個ずつのテストケースがあり、各テストケースの得点の合計がその問題に対する提出の得点となる。 一つ以上のテストケースで不正な出力や制限時間超過をした場合、提出全体の判定がWATLEとなる。 各問題に対して獲得した最高得点の総和で最終順位が決定され、コンテスト終了後のシステムテストは行われない。 同じ得点を複数のチームが得た場合、提出時刻に関わらず同じ順位となる。


入力

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

N K C
g_{0,0} \cdots g_{0,N-1}
\vdots
g_{N-1,0} \cdots g_{N-1,N-1}

入力は以下の制約を満たす。

  • レイヤーの一辺の長さ NN=32 で固定されている。
  • レイヤーの枚数 K2 以上 5 以下の整数である。
  • 色の種類数 C2 以上 4 以下の整数である。
  • g_{i,j} は目標画像のピクセル (i,j) の色を表す 0 以上 C 以下の整数である。
    • 目標画像において、1,\cdots,C のすべての色が出現するとは限らない。
    • 目標画像における非透明なピクセル数は N^2/2 以上である。

出力

行った操作を実行順に、以下の形式で 1 行ずつ標準出力に出力せよ。

  • \mathrm{paint}(k,i,j,x)
0 k i j x
  • \mathrm{copy}(k,h,r,\Delta i,\Delta j)
1 k h r \Delta i \Delta j
  • \mathrm{clear}(k)
2 k

入力生成方法

\mathrm{rand}(L,U) を、L 以上 U 以下の整数を一様ランダムに生成する関数とする。 非透明なピクセル全体からなる集合が上下左右 4 方向に連結であるとき、そのレイヤーの非透明なピクセルは連結であると呼ぶ。

A 問題の入力は以下のように生成される。

N, K, C の生成

N=32 で固定である。 K=\mathrm{rand}(2,5)C=\mathrm{rand}(2,4) により生成される。

g の生成

まず、K'=\mathrm{rand}(1,2K) を生成する。 K' 枚の透明なレイヤーを用意し、レイヤー k のピクセル (i,j) の色を c(k,i,j) とする。 c(0,N/2,N/2)=1 とする。 また、パラメータ p=\mathrm{rand}(2,5) を生成する。

以下の処理を繰り返す。ある操作によって更新されたレイヤーの非透明なピクセル数が初めて N^2/2 以上となった時点で処理を終了し、そのレイヤーの画像、すなわち各ピクセルの色を g_{i,j} とする。

各反復では、p/10 の確率で paint 操作を、1-p/10 の確率で copy 操作を行う。

paint 操作:

k=\mathrm{rand}(0,K'-1) によりレイヤーを選択する。 レイヤー k が透明な場合は (i,j)=(N/2,N/2) を、そうでない場合は (i,j)=(\mathrm{rand}(0,N-1),\mathrm{rand}(0,N-1)) を生成する。 すべてのレイヤーにおける色 x のピクセル数を \mathrm{num}(x) とする。 \mathrm{num}(x) が最小となる色 x\in\{1,\cdots,C\} の中から、一様ランダムに 1 つ選ぶ。 仮に c(k,i,j)=x と更新し、レイヤー k の非透明なピクセルが連結であるかを判定する。 連結でない場合はこの試行を破棄し、(i,j) の生成からやり直す。

copy 操作:

コピー先のレイヤー k=\mathrm{rand}(0,K'-1) を生成する。 非透明なピクセルを持つレイヤー h を一様ランダムに選択する。 回転回数 r=\mathrm{rand}(0,3) を生成する。 レイヤー h を時計回りに 90 度回転する操作を r 回行って得られるレイヤーを h' とする。 h' の非透明なピクセルのうち、i 座標の最小値を i_0、最大値を i_1j 座標の最小値を j_0、最大値を j_1 とする。 シフト量 (\Delta i,\Delta j)(\mathrm{rand}(-i_0,N-1-i_1),\mathrm{rand}(-j_0,N-1-j_1)) により生成する。 操作 \mathrm{copy}(k,h,r,\Delta i,\Delta j) を仮に適用し、レイヤー k の非透明なピクセルが連結であるかを判定する。 連結でない場合はこの試行を破棄し、k の選択はそのままで、レイヤー h の選択からやり直す。

B 問題について

B 問題の入力は、各チームが自ら作成して提出によって差し替えることができる。 作成した入力の提出方法については、C 問題のページを参照せよ。

各チームは4つの入力を提出する。提出された4つの入力のうち、ランダムに1件が全チームに公開され、残りの3件がジャッジに使用される。 入力の公開およびジャッジの開始は、コンテスト開始から2時間20分後程度を目安としている。 準備が整い次第、全体アナウンスを行う。

入力を提出しなかったチームの分は、前述の A 問題の入力生成方法に従ってランダムに生成された4つの入力が代わりに用いられる。

なお、自分のチームが提出した入力は既知であるため、対応する出力を事前に計算して解答プログラムに埋め込むことも許される。

C 問題への提出は何度でも行うことができる。ただし、各チームについて、コンテスト開始から 120 分未満 に提出されたもので ACを獲得した提出のうち、最後の1件のみが使用される。

ツール(入力ジェネレータ・スコア計算)

コンテスト期間中に、チーム外とのビジュアライズ結果の共有や解法・考察に関する言及は禁止されています。ご注意下さい。


入力例 1

32 4 2
0 0 0 0 0 0 0 0 2 1 1 1 0 0 2 1 2 1 2 0 0 2 1 2 1 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 2 2 1 2 1 1 0 1 2 1 2 1 1 2 2 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 2 2 2 2 1 0 0 2 1 2 2 1 0 0 1 1 0 0 0 0 0 2 0
0 0 0 0 0 2 0 0 1 1 2 0 1 1 1 1 2 0 0 2 2 1 1 2 2 0 0 0 0 0 1 0
0 0 0 0 0 0 2 1 1 2 1 1 2 1 1 1 0 1 2 1 1 1 2 1 1 2 2 2 1 2 1 0
0 0 0 0 2 1 1 1 1 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 2 1 0
0 0 0 0 0 0 0 1 1 1 2 2 1 2 1 2 1 2 1 1 2 1 2 1 1 1 1 2 1 2 0 0
0 0 0 2 2 0 1 2 1 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 1 1 1 2 2 0 0
0 0 0 1 2 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 0
0 0 0 2 2 0 2 1 2 2 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2
0 0 8 20 1
0 0 8 21 1
0 0 8 22 2
0 0 8 23 2
0 0 8 24 2
0 0 8 25 1
0 0 8 26 1
0 0 8 27 1
0 0 8 28 2
0 0 8 29 2
0 0 9 3 1
0 0 9 4 2
0 0 9 5 1
0 0 9 6 1
0 0 9 7 1
0 0 9 8 1
0 0 9 9 1
0 0 9 10 1
0 0 9 11 1
0 0 9 12 1
0 0 9 13 2
0 0 9 14 2
0 0 9 15 2
0 0 9 16 1
0 0 9 17 1
0 0 9 18 2
0 0 9 19 1
0 0 9 20 2
0 0 9 21 1
0 0 9 22 1
0 0 9 23 2
0 0 9 24 1
0 0 9 25 2
0 0 9 26 1
0 0 9 27 2
0 0 9 28 1
0 0 9 29 1
0 0 9 30 2
0 0 10 3 2
0 0 10 4 2
0 0 10 6 2
0 0 10 7 1
0 0 10 8 2
0 0 10 9 2
0 0 10 10 2
0 0 10 11 1
0 0 10 12 1
0 0 10 13 1
0 0 10 14 2
0 0 10 15 1
0 0 10 16 1
0 0 10 17 1
0 0 10 18 1
0 0 10 19 1
0 0 10 20 2
0 0 10 21 1
0 0 10 22 1
0 0 10 23 1
0 0 10 24 2
0 0 10 25 2
0 0 10 26 1
0 0 10 30 2
0 0 11 3 1
0 0 11 4 2
0 0 11 5 1
0 0 11 6 1
0 0 11 7 2
0 0 11 8 1
0 0 11 9 2
0 0 11 10 1
0 0 11 11 2
0 0 11 12 1
0 0 11 13 1
0 0 11 14 2
0 0 11 15 1
0 0 11 16 1
0 0 11 17 1
0 0 11 18 1
0 0 11 19 1
0 0 11 20 1
0 0 11 21 2
0 0 11 22 1
0 0 11 23 2
0 0 11 24 1
0 0 11 25 1
0 0 11 26 2
0 0 12 3 2
0 0 12 4 1
0 0 12 5 1
0 0 12 6 2
0 0 12 7 2
0 0 12 8 2
0 0 12 9 1
0 0 12 10 2
0 0 12 11 1
0 0 12 12 1
0 0 12 13 2
0 0 12 14 1
0 0 12 15 2
0 0 12 16 1
0 0 12 17 1
0 0 12 18 2
0 0 12 19 1
0 0 12 20 1
0 0 12 21 1
0 0 12 22 1
0 0 12 23 2
0 0 12 24 1
0 0 12 25 2
0 0 12 26 1
0 0 12 27 1
0 0 12 28 2
0 0 13 3 2
0 0 13 4 2
0 0 13 5 2
0 0 13 6 2
0 0 13 7 2
0 0 13 8 1
0 0 13 9 1
0 0 13 10 1
0 0 13 11 1
0 0 13 12 2
0 0 13 13 2
0 0 13 14 2
0 0 13 15 1
0 0 13 16 1
0 0 13 17 2
0 0 13 18 1
0 0 13 19 1
0 0 13 20 2
0 0 13 21 1
0 0 13 22 2
0 0 13 23 2
0 0 13 24 1
0 0 13 25 2
0 0 13 26 2
0 0 14 4 2
0 0 14 5 1
0 0 14 6 2
0 0 14 7 1
0 0 14 8 1
0 0 14 9 1
0 0 14 10 1
0 0 14 11 2
0 0 14 12 1
0 0 14 13 1
0 0 14 14 1
0 0 14 15 2
0 0 14 16 2
0 0 14 17 1
0 0 14 18 1
0 0 14 19 2
0 0 14 20 2
0 0 14 21 1
0 0 14 22 2
0 0 14 23 1
0 0 14 24 1
0 0 14 25 1
0 0 14 26 1
0 0 14 27 2
0 0 15 3 2
0 0 15 4 2
0 0 15 5 2
0 0 15 6 2
0 0 15 7 1
0 0 15 8 1
0 0 15 9 1
0 0 15 10 1
0 0 15 11 1
0 0 15 12 2
0 0 15 13 2
0 0 15 14 1
0 0 15 15 2
0 0 15 16 2
0 0 15 17 2
0 0 15 18 1
0 0 15 19 2
0 0 15 20 1
0 0 15 21 1
0 0 15 22 2
0 0 15 23 2
0 0 15 24 2
0 0 15 25 2
0 0 15 26 2
0 0 15 27 1
0 0 16 3 1
0 0 16 4 1
0 0 16 5 1
0 0 16 6 1
0 0 16 7 1
0 0 16 8 1
0 0 16 9 2
0 0 16 10 1
0 0 16 11 1
0 0 16 12 1
0 0 16 13 1
0 0 16 14 1
0 0 16 15 2
0 0 16 16 2
0 0 16 17 1
0 0 16 18 2
0 0 16 19 2
0 0 16 20 2
0 0 16 21 1
0 0 16 22 1
0 0 16 23 2
0 0 16 24 1
0 0 16 25 2
0 0 17 3 2
0 0 17 4 2
0 0 17 6 2
0 0 17 7 1
0 0 17 8 2
0 0 17 9 1
0 0 17 10 1
0 0 17 11 2
0 0 17 12 2
0 0 17 13 2
0 0 17 14 2
0 0 17 15 1
0 0 17 16 1
0 0 17 17 1
0 0 17 18 1
0 0 17 19 1
0 0 17 20 2
0 0 17 21 1
0 0 17 22 1
0 0 17 23 1
0 0 17 24 2
0 0 17 25 2
0 0 18 3 1
0 0 18 4 2
0 0 18 5 1
0 0 18 7 1
0 0 18 8 1
0 0 18 9 1
0 0 18 10 2
0 0 18 11 1
0 0 18 12 1
0 0 18 13 1
0 0 18 14 1
0 0 18 15 1
0 0 18 16 1
0 0 18 17 1
0 0 18 18 1
0 0 18 19 1
0 0 18 20 1
0 0 18 21 2
0 0 18 22 1
0 0 18 24 1
0 0 18 25 1
0 0 18 26 2
0 0 19 3 2
0 0 19 4 1
0 0 19 5 1
0 0 19 6 2
0 0 19 7 2
0 0 19 8 2
0 0 19 9 1
0 0 19 10 2
0 0 19 11 2
0 0 19 12 1
0 0 19 13 1
0 0 19 14 2
0 0 19 15 2
0 0 19 16 1
0 0 19 17 2
0 0 19 18 2
0 0 19 19 1
0 0 19 20 2
0 0 19 21 1
0 0 19 22 1
0 0 19 23 1
0 0 19 24 1
0 0 19 25 2
0 0 19 26 1
0 0 20 4 2
0 0 20 5 2
0 0 20 6 1
0 0 20 7 1
0 0 20 8 1
0 0 20 9 1
0 0 20 10 1
0 0 20 11 2
0 0 20 12 1
0 0 20 13 1
0 0 20 14 1
0 0 20 15 1
0 0 20 16 1
0 0 20 17 2
0 0 20 18 2
0 0 20 19 1
0 0 20 20 2
0 0 20 21 2
0 0 20 22 2
0 0 20 25 2
0 0 20 26 2
0 0 21 4 2
0 0 21 5 1
0 0 21 6 2
0 0 21 7 1
0 0 21 8 1
0 0 21 9 1
0 0 21 10 1
0 0 21 11 2
0 0 21 12 1
0 0 21 13 2
0 0 21 14 1
0 0 21 15 2
0 0 21 16 1
0 0 21 17 1
0 0 21 18 2
0 0 21 19 2
0 0 21 21 1
0 0 21 22 1
0 0 21 23 1
0 0 21 24 1
0 0 21 25 1
0 0 21 26 1
0 0 22 3 1
0 0 22 4 1
0 0 22 5 2
0 0 22 6 2
0 0 22 7 2
0 0 22 8 1
0 0 22 9 1
0 0 22 10 2
0 0 22 11 1
0 0 22 12 1
0 0 22 13 1
0 0 22 14 2
0 0 22 15 1
0 0 22 16 1
0 0 22 17 2
0 0 22 18 1
0 0 22 19 1
0 0 22 20 1
0 0 22 21 1
0 0 22 25 2
0 0 22 26 2
0 0 23 3 1
0 0 23 5 2
0 0 23 6 1
0 0 23 7 1
0 0 23 8 1
0 0 23 9 1
0 0 23 10 1
0 0 23 11 2
0 0 23 12 2
0 0 23 13 1
0 0 23 14 1
0 0 23 15 1
0 0 23 16 1
0 0 23 17 1
0 0 23 18 2
0 0 23 19 1
0 0 23 20 2
0 0 23 21 1
0 0 23 22 2
0 0 24 3 1
0 0 24 6 2
0 0 24 7 1
0 0 24 8 1
0 0 24 9 2
0 0 24 10 2
0 0 24 11 1
0 0 24 12 2
0 0 24 13 2
0 0 24 14 1
0 0 24 15 1
0 0 24 16 2
0 0 24 17 2
0 0 24 18 1
0 0 24 19 2
0 0 24 20 2
0 0 24 21 1
0 0 24 22 2
0 0 25 3 2
0 0 25 7 1
0 0 25 8 2
0 0 25 9 1
0 0 25 10 1
0 0 25 11 1
0 0 25 12 1
0 0 25 14 1
0 0 25 15 2
0 0 25 16 1
0 0 25 17 1
0 0 25 18 1
0 0 25 19 1
0 0 26 6 2
0 0 26 7 1
0 0 26 8 1
0 0 26 9 1
0 0 26 10 1
0 0 26 13 2
0 0 26 14 1
0 0 26 15 1
0 0 26 16 1
0 0 26 17 1
0 0 27 9 1
0 0 27 10 2
0 0 27 11 2
0 0 27 12 1
0 0 27 13 2
0 0 27 16 1
0 0 27 17 2
0 0 27 18 2
0 0 27 19 1
0 0 27 20 2
0 0 28 7 1
0 0 28 8 1
0 0 28 9 2
0 0 28 10 1
0 0 28 11 2
0 0 28 12 1
0 0 28 14 1
0 0 28 15 1
0 0 28 16 2
0 0 28 17 1
0 0 28 18 2
0 0 28 19 1
0 0 29 4 2
0 0 29 5 1
0 0 29 6 2
0 0 29 7 2
0 0 29 8 1
0 0 29 9 2
0 0 29 10 2
0 0 29 11 2
0 0 29 12 1
0 0 29 13 2
0 0 29 14 2
0 0 29 15 1
0 0 29 16 2
0 0 29 17 2
0 0 29 18 1
0 0 30 4 2
0 0 30 5 1
0 0 30 6 2
0 0 30 7 1
0 0 30 8 2
0 0 30 11 2
0 0 30 12 1
0 0 30 13 2
0 0 30 14 1
0 0 30 15 2
0 0 30 18 1
0 0 30 19 1
0 0 30 20 1
0 0 30 21 2

Story

Master painter Takahashi is working on a new piece of art using image editing software. While creating the work, he can use multiple layers, gradually add to the image, rotate and overlay the contents of another layer, or clear a layer that is no longer needed. Your task is to find a procedure that completes the target image in as few operations as possible.

Problem Statement

There are K layers, each consisting of N\times N pixels. The layers are numbered 0,\cdots,K-1. Let the coordinates of the top-left pixel be (0,0), and define the coordinates of the pixel reached by moving i pixels downward and j pixels to the right from there as (i,j).

There are C available colors, numbered 1,\cdots,C. Let c(k,i,j) denote the color of pixel (i,j) on layer k. If c(k,i,j)=0, that pixel is transparent.

The target image is given by the color g_{i,j} of each pixel. The target image is considered complete when c(0,i,j)=g_{i,j} holds for all (i,j). The states of the other layers do not matter.

Initially, all layers are transparent, that is, c(k,i,j)=0 for all k,i,j. Complete the target image by repeating the following operations at most N^2 times.

  • \mathrm{paint}(k,i,j,x): Specify a layer k\in\{0,\cdots,K-1\}, a pixel (i,j), and a color x\in\{0,\cdots,C\}, and change c(k,i,j) to x. If x=0 is specified, that pixel becomes transparent again.
  • \mathrm{copy}(k,h,r,\Delta i,\Delta j): Specify layers k,h\in\{0,\cdots,K-1\}, an integer r\in\{0,\cdots,3\}, \Delta i\in\{-N+1,\cdots,N-1\}, and \Delta j\in\{-N+1,\cdots,N-1\}. Let h' be the layer obtained by rotating layer h clockwise by 90 degrees exactly r times. Note that layer h itself is not modified. Place h' so that its top-left pixel corresponds to pixel (\Delta i,\Delta j) of layer k, and overlay it. Then, overwrite layer k with all non-transparent pixels of h'. That is, for all (i,j) such that c(h',i,j)\neq 0, update c(k,\Delta i+i,\Delta j+j)=c(h',i,j). If this operation would paint any pixel outside the bounds of layer k, the output is judged as WA. It is allowed that k=h.
  • \mathrm{clear}(k): Make all pixels of layer k transparent.

Scoring

Let T be the number of operations. Let U be the number of non-transparent pixels in the target image, that is, the number of (i,j) satisfying g_{i,j}\neq 0. Then, the score is calculated as follows:

\[ \mathrm{round}\left(10^6\times \left(1+\log_2 \frac{U}{T}\right)\right) \]

The problem is divided into two subproblems: A and B, based on different input generation methods. Each subproblem contains 150 test cases, and the total score for a submission to that subproblem is the sum of the scores from all test cases in it. If your submission produces an illegal output or exceeds the time limit for some test cases, the submission itself will be judged as WA or TLE , and the score of the submission will be zero.

The final ranking is determined by the sum of the highest scores obtained for each subproblem, and there will be no system test after the contest. If more than one team gets the same score, they will be ranked in the same place regardless of the submission time.


Input

The input is given from Standard Input in the following format.

N K C
g_{0,0} \cdots g_{0,N-1}
\vdots
g_{N-1,0} \cdots g_{N-1,N-1}

The input satisfies the following constraints.

  • The side length N of each layer is fixed to N=32.
  • K is an integer between 2 and 5, inclusive, representing the number of layers.
  • C is an integer between 2 and 4, inclusive, representing the number of colors.
  • g_{i,j} is an integer between 0 and C, inclusive, representing the color of pixel (i,j) in the target image.
    • Not all colors 1,\cdots,C necessarily appear in the target image.
    • The number of non-transparent pixels in the target image is at least N^2/2.

Output

Print the operations you perform to Standard Output in the order they are executed, one per line, in the following format.

  • \mathrm{paint}(k,i,j,x)
0 k i j x
  • \mathrm{copy}(k,h,r,\Delta i,\Delta j)
1 k h r \Delta i \Delta j
  • \mathrm{clear}(k)
2 k

Input Generation

Let \mathrm{rand}(L,U) be a function that generates an integer uniformly at random between L and U, inclusive. The non-transparent pixels of a layer are said to be connected if the set of all non-transparent pixels is connected under 4-neighbor adjacency.

Inputs for Problem A are generated as follows.

Generation of N, K, and C

N is fixed to 32. K=\mathrm{rand}(2,5) and C=\mathrm{rand}(2,4).

Generation of g

First, generate K'=\mathrm{rand}(1,2K). Prepare K' transparent layers, and let c(k,i,j) denote the color of pixel (i,j) on layer k. Set c(0,N/2,N/2)=1. Also, generate a parameter p=\mathrm{rand}(2,5).

Repeat the following process. Terminate the process when, for the first time, the number of non-transparent pixels in the layer updated by some operation becomes at least N^2/2, and let the image of that layer, that is, the color of each pixel, be g_{i,j}.

In each iteration, perform a paint operation with probability p/10, and a copy operation with probability 1-p/10.

paint operation:

Choose a layer by k=\mathrm{rand}(0,K'-1). If layer k is transparent, set (i,j)=(N/2,N/2); otherwise, generate (i,j)=(\mathrm{rand}(0,N-1),\mathrm{rand}(0,N-1)). Let \mathrm{num}(x) be the number of pixels of color x over all layers. Choose one color uniformly at random from the colors x\in\{1,\cdots,C\} that minimize \mathrm{num}(x). Tentatively update c(k,i,j)=x, and check whether the non-transparent pixels of layer k are connected. If they are not connected, discard this trial and retry from the generation of (i,j).

copy operation:

Generate the destination layer k=\mathrm{rand}(0,K'-1). Choose a layer h with non-transparent pixels uniformly at random. Generate the number of rotations r=\mathrm{rand}(0,3). Let h' be the layer obtained by rotating layer h clockwise by 90 degrees exactly r times. Among the non-transparent pixels of h', let the minimum and maximum i-coordinates be i_0 and i_1, and the minimum and maximum j-coordinates be j_0 and j_1. Generate the shift amount (\Delta i,\Delta j) by (\mathrm{rand}(-i_0,N-1-i_1),\mathrm{rand}(-j_0,N-1-j_1)). Tentatively apply the operation \mathrm{copy}(k,h,r,\Delta i,\Delta j), and check whether the non-transparent pixels of layer k are connected. If they are not connected, discard this trial and retry from the selection of layer h, keeping the choice of k unchanged.

Regarding Problem B

For Problem B, each team may create their own inputs and overwrite the default ones by submitting them. Refer to the page for Problem C for instructions on how to submit your inputs.

Each team may submit four inputs. Among the four submitted inputs, one is randomly selected and made public to all teams, while the remaining three are used for judging.

The input publication and the start of judging are scheduled to take place approximately 2 hours and 20 minutes after the contest begins. An announcement will be made to all participants once the system is ready.

For any team that does not submit their own inputs, four inputs will be generated randomly according to the input generation procedure described earlier.

Since each team knows the contents of the inputs they submitted, it is allowed to precompute the corresponding outputs and embed them into the solution program.

Submissions to Problem C may be made as many times as desired. However, for each team, only the last submission made within 120 minutes from the start of the contest that receives AC will be used for judging.

Tools (Input generator and score calculation)

Please be aware that sharing visualization results or discussing solutions/ideas outside of the team during the contest is prohibited.


Sample Input 1

32 4 2
0 0 0 0 0 0 0 0 2 1 1 1 0 0 2 1 2 1 2 0 0 2 1 2 1 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 2 2 1 2 1 1 0 1 2 1 2 1 1 2 2 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 1 2 2 2 2 1 0 0 2 1 2 2 1 0 0 1 1 0 0 0 0 0 2 0
0 0 0 0 0 2 0 0 1 1 2 0 1 1 1 1 2 0 0 2 2 1 1 2 2 0 0 0 0 0 1 0
0 0 0 0 0 0 2 1 1 2 1 1 2 1 1 1 0 1 2 1 1 1 2 1 1 2 2 2 1 2 1 0
0 0 0 0 2 1 1 1 1 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 2 1 0
0 0 0 0 0 0 0 1 1 1 2 2 1 2 1 2 1 2 1 1 2 1 2 1 1 1 1 2 1 2 0 0
0 0 0 2 2 0 1 2 1 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 1 1 1 2 2 0 0
0 0 0 1 2 1 1 1 1 1 1 1 1 2 2 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 0
0 0 0 2 2 0 2 1 2 2 2 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 0 0 0 2 0
0 0 0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 24 2
0 0 8 25 1
0 0 8 26 1
0 0 8 27 1
0 0 8 28 2
0 0 8 29 2
0 0 9 3 1
0 0 9 4 2
0 0 9 5 1
0 0 9 6 1
0 0 9 7 1
0 0 9 8 1
0 0 9 9 1
0 0 9 10 1
0 0 9 11 1
0 0 9 12 1
0 0 9 13 2
0 0 9 14 2
0 0 9 15 2
0 0 9 16 1
0 0 9 17 1
0 0 9 18 2
0 0 9 19 1
0 0 9 20 2
0 0 9 21 1
0 0 9 22 1
0 0 9 23 2
0 0 9 24 1
0 0 9 25 2
0 0 9 26 1
0 0 9 27 2
0 0 9 28 1
0 0 9 29 1
0 0 9 30 2
0 0 10 3 2
0 0 10 4 2
0 0 10 6 2
0 0 10 7 1
0 0 10 8 2
0 0 10 9 2
0 0 10 10 2
0 0 10 11 1
0 0 10 12 1
0 0 10 13 1
0 0 10 14 2
0 0 10 15 1
0 0 10 16 1
0 0 10 17 1
0 0 10 18 1
0 0 10 19 1
0 0 10 20 2
0 0 10 21 1
0 0 10 22 1
0 0 10 23 1
0 0 10 24 2
0 0 10 25 2
0 0 10 26 1
0 0 10 30 2
0 0 11 3 1
0 0 11 4 2
0 0 11 5 1
0 0 11 6 1
0 0 11 7 2
0 0 11 8 1
0 0 11 9 2
0 0 11 10 1
0 0 11 11 2
0 0 11 12 1
0 0 11 13 1
0 0 11 14 2
0 0 11 15 1
0 0 11 16 1
0 0 11 17 1
0 0 11 18 1
0 0 11 19 1
0 0 11 20 1
0 0 11 21 2
0 0 11 22 1
0 0 11 23 2
0 0 11 24 1
0 0 11 25 1
0 0 11 26 2
0 0 12 3 2
0 0 12 4 1
0 0 12 5 1
0 0 12 6 2
0 0 12 7 2
0 0 12 8 2
0 0 12 9 1
0 0 12 10 2
0 0 12 11 1
0 0 12 12 1
0 0 12 13 2
0 0 12 14 1
0 0 12 15 2
0 0 12 16 1
0 0 12 17 1
0 0 12 18 2
0 0 12 19 1
0 0 12 20 1
0 0 12 21 1
0 0 12 22 1
0 0 12 23 2
0 0 12 24 1
0 0 12 25 2
0 0 12 26 1
0 0 12 27 1
0 0 12 28 2
0 0 13 3 2
0 0 13 4 2
0 0 13 5 2
0 0 13 6 2
0 0 13 7 2
0 0 13 8 1
0 0 13 9 1
0 0 13 10 1
0 0 13 11 1
0 0 13 12 2
0 0 13 13 2
0 0 13 14 2
0 0 13 15 1
0 0 13 16 1
0 0 13 17 2
0 0 13 18 1
0 0 13 19 1
0 0 13 20 2
0 0 13 21 1
0 0 13 22 2
0 0 13 23 2
0 0 13 24 1
0 0 13 25 2
0 0 13 26 2
0 0 14 4 2
0 0 14 5 1
0 0 14 6 2
0 0 14 7 1
0 0 14 8 1
0 0 14 9 1
0 0 14 10 1
0 0 14 11 2
0 0 14 12 1
0 0 14 13 1
0 0 14 14 1
0 0 14 15 2
0 0 14 16 2
0 0 14 17 1
0 0 14 18 1
0 0 14 19 2
0 0 14 20 2
0 0 14 21 1
0 0 14 22 2
0 0 14 23 1
0 0 14 24 1
0 0 14 25 1
0 0 14 26 1
0 0 14 27 2
0 0 15 3 2
0 0 15 4 2
0 0 15 5 2
0 0 15 6 2
0 0 15 7 1
0 0 15 8 1
0 0 15 9 1
0 0 15 10 1
0 0 15 11 1
0 0 15 12 2
0 0 15 13 2
0 0 15 14 1
0 0 15 15 2
0 0 15 16 2
0 0 15 17 2
0 0 15 18 1
0 0 15 19 2
0 0 15 20 1
0 0 15 21 1
0 0 15 22 2
0 0 15 23 2
0 0 15 24 2
0 0 15 25 2
0 0 15 26 2
0 0 15 27 1
0 0 16 3 1
0 0 16 4 1
0 0 16 5 1
0 0 16 6 1
0 0 16 7 1
0 0 16 8 1
0 0 16 9 2
0 0 16 10 1
0 0 16 11 1
0 0 16 12 1
0 0 16 13 1
0 0 16 14 1
0 0 16 15 2
0 0 16 16 2
0 0 16 17 1
0 0 16 18 2
0 0 16 19 2
0 0 16 20 2
0 0 16 21 1
0 0 16 22 1
0 0 16 23 2
0 0 16 24 1
0 0 16 25 2
0 0 17 3 2
0 0 17 4 2
0 0 17 6 2
0 0 17 7 1
0 0 17 8 2
0 0 17 9 1
0 0 17 10 1
0 0 17 11 2
0 0 17 12 2
0 0 17 13 2
0 0 17 14 2
0 0 17 15 1
0 0 17 16 1
0 0 17 17 1
0 0 17 18 1
0 0 17 19 1
0 0 17 20 2
0 0 17 21 1
0 0 17 22 1
0 0 17 23 1
0 0 17 24 2
0 0 17 25 2
0 0 18 3 1
0 0 18 4 2
0 0 18 5 1
0 0 18 7 1
0 0 18 8 1
0 0 18 9 1
0 0 18 10 2
0 0 18 11 1
0 0 18 12 1
0 0 18 13 1
0 0 18 14 1
0 0 18 15 1
0 0 18 16 1
0 0 18 17 1
0 0 18 18 1
0 0 18 19 1
0 0 18 20 1
0 0 18 21 2
0 0 18 22 1
0 0 18 24 1
0 0 18 25 1
0 0 18 26 2
0 0 19 3 2
0 0 19 4 1
0 0 19 5 1
0 0 19 6 2
0 0 19 7 2
0 0 19 8 2
0 0 19 9 1
0 0 19 10 2
0 0 19 11 2
0 0 19 12 1
0 0 19 13 1
0 0 19 14 2
0 0 19 15 2
0 0 19 16 1
0 0 19 17 2
0 0 19 18 2
0 0 19 19 1
0 0 19 20 2
0 0 19 21 1
0 0 19 22 1
0 0 19 23 1
0 0 19 24 1
0 0 19 25 2
0 0 19 26 1
0 0 20 4 2
0 0 20 5 2
0 0 20 6 1
0 0 20 7 1
0 0 20 8 1
0 0 20 9 1
0 0 20 10 1
0 0 20 11 2
0 0 20 12 1
0 0 20 13 1
0 0 20 14 1
0 0 20 15 1
0 0 20 16 1
0 0 20 17 2
0 0 20 18 2
0 0 20 19 1
0 0 20 20 2
0 0 20 21 2
0 0 20 22 2
0 0 20 25 2
0 0 20 26 2
0 0 21 4 2
0 0 21 5 1
0 0 21 6 2
0 0 21 7 1
0 0 21 8 1
0 0 21 9 1
0 0 21 10 1
0 0 21 11 2
0 0 21 12 1
0 0 21 13 2
0 0 21 14 1
0 0 21 15 2
0 0 21 16 1
0 0 21 17 1
0 0 21 18 2
0 0 21 19 2
0 0 21 21 1
0 0 21 22 1
0 0 21 23 1
0 0 21 24 1
0 0 21 25 1
0 0 21 26 1
0 0 22 3 1
0 0 22 4 1
0 0 22 5 2
0 0 22 6 2
0 0 22 7 2
0 0 22 8 1
0 0 22 9 1
0 0 22 10 2
0 0 22 11 1
0 0 22 12 1
0 0 22 13 1
0 0 22 14 2
0 0 22 15 1
0 0 22 16 1
0 0 22 17 2
0 0 22 18 1
0 0 22 19 1
0 0 22 20 1
0 0 22 21 1
0 0 22 25 2
0 0 22 26 2
0 0 23 3 1
0 0 23 5 2
0 0 23 6 1
0 0 23 7 1
0 0 23 8 1
0 0 23 9 1
0 0 23 10 1
0 0 23 11 2
0 0 23 12 2
0 0 23 13 1
0 0 23 14 1
0 0 23 15 1
0 0 23 16 1
0 0 23 17 1
0 0 23 18 2
0 0 23 19 1
0 0 23 20 2
0 0 23 21 1
0 0 23 22 2
0 0 24 3 1
0 0 24 6 2
0 0 24 7 1
0 0 24 8 1
0 0 24 9 2
0 0 24 10 2
0 0 24 11 1
0 0 24 12 2
0 0 24 13 2
0 0 24 14 1
0 0 24 15 1
0 0 24 16 2
0 0 24 17 2
0 0 24 18 1
0 0 24 19 2
0 0 24 20 2
0 0 24 21 1
0 0 24 22 2
0 0 25 3 2
0 0 25 7 1
0 0 25 8 2
0 0 25 9 1
0 0 25 10 1
0 0 25 11 1
0 0 25 12 1
0 0 25 14 1
0 0 25 15 2
0 0 25 16 1
0 0 25 17 1
0 0 25 18 1
0 0 25 19 1
0 0 26 6 2
0 0 26 7 1
0 0 26 8 1
0 0 26 9 1
0 0 26 10 1
0 0 26 13 2
0 0 26 14 1
0 0 26 15 1
0 0 26 16 1
0 0 26 17 1
0 0 27 9 1
0 0 27 10 2
0 0 27 11 2
0 0 27 12 1
0 0 27 13 2
0 0 27 16 1
0 0 27 17 2
0 0 27 18 2
0 0 27 19 1
0 0 27 20 2
0 0 28 7 1
0 0 28 8 1
0 0 28 9 2
0 0 28 10 1
0 0 28 11 2
0 0 28 12 1
0 0 28 14 1
0 0 28 15 1
0 0 28 16 2
0 0 28 17 1
0 0 28 18 2
0 0 28 19 1
0 0 29 4 2
0 0 29 5 1
0 0 29 6 2
0 0 29 7 2
0 0 29 8 1
0 0 29 9 2
0 0 29 10 2
0 0 29 11 2
0 0 29 12 1
0 0 29 13 2
0 0 29 14 2
0 0 29 15 1
0 0 29 16 2
0 0 29 17 2
0 0 29 18 1
0 0 30 4 2
0 0 30 5 1
0 0 30 6 2
0 0 30 7 1
0 0 30 8 2
0 0 30 11 2
0 0 30 12 1
0 0 30 13 2
0 0 30 14 1
0 0 30 15 2
0 0 30 18 1
0 0 30 19 1
0 0 30 20 1
0 0 30 21 2
B - Copy-Paste Painting (B)

Time Limit: 2 sec / Memory Limit: 1024 MiB

この問題はA問題と同じで入力のみ異なります。 詳細はA問題を参照下さい。
This problem is the same as Problem A, differing only in input. See Problem A for details.