結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー wotsushiwotsushi
提出日時 2017-04-16 10:47:39
言語 Ruby
(3.3.0)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 578 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 11,292 KB
実行使用メモリ 15,420 KB
最終ジャッジ日時 2023-09-26 08:58:24
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
15,080 KB
testcase_01 AC 80 ms
15,032 KB
testcase_02 AC 87 ms
15,176 KB
testcase_03 AC 81 ms
15,296 KB
testcase_04 AC 80 ms
15,292 KB
testcase_05 AC 81 ms
15,148 KB
testcase_06 AC 82 ms
15,176 KB
testcase_07 AC 84 ms
15,332 KB
testcase_08 AC 84 ms
15,272 KB
testcase_09 AC 83 ms
15,316 KB
testcase_10 AC 84 ms
15,280 KB
testcase_11 AC 85 ms
15,420 KB
testcase_12 AC 76 ms
15,172 KB
testcase_13 AC 77 ms
15,280 KB
testcase_14 AC 77 ms
15,076 KB
testcase_15 AC 79 ms
15,280 KB
testcase_16 AC 80 ms
15,272 KB
testcase_17 AC 82 ms
15,208 KB
testcase_18 AC 78 ms
15,176 KB
testcase_19 AC 77 ms
15,040 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
    f((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