結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー wotsushiwotsushi
提出日時 2017-04-16 10:42:36
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 557 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-09-26 08:58:21
合計ジャッジ時間 3,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,084 KB
testcase_01 AC 80 ms
15,204 KB
testcase_02 WA -
testcase_03 AC 80 ms
15,044 KB
testcase_04 AC 82 ms
15,108 KB
testcase_05 AC 82 ms
15,168 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 77 ms
15,340 KB
testcase_13 AC 76 ms
15,204 KB
testcase_14 AC 78 ms
15,264 KB
testcase_15 AC 78 ms
15,088 KB
testcase_16 AC 79 ms
15,112 KB
testcase_17 AC 78 ms
15,052 KB
testcase_18 AC 77 ms
14,996 KB
testcase_19 AC 80 ms
15,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a = (1..4).map {gets.split.map(&:to_i)}
D = [*0...4].product([*0...4])
def f(x)
  i1, j1 = D.find {|i, j| x[i][j] == 0}
  i2, j2 = D.find {|i, j| x[i][j] == 4 * i1 + j1 + 1} || [-1, -1]
  if (i2 - i1).abs + (j2 - j1).abs != 1
    x
  else
    (0...4).map {|i|
      (0...4).map {|j|
        if [i, j] == [i1, j1]
          x[i2][j2]
        elsif [i, j] == [i2, j2]
          0
        else
          x[i][j]
        end
      }}
  end
end
ans = if D.all? {|i, j| f(a)[i][j] == (4 * i + j + 1) % 16}
        "Yes"
      else
        "No"
      end
puts ans
0