結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-05 21:18:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 921 bytes |
| コンパイル時間 | 256 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 60,244 KB |
| 最終ジャッジ日時 | 2024-11-06 08:34:34 |
| 合計ジャッジ時間 | 2,074 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 12 WA * 5 |
ソースコード
ls = []
for i in range(4):
ls += list(map(int,input().split()))
ls = tuple(ls)
kls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]
moveto = [-4,-1,1,4]
als = set()
def dfs(ls0):
als.add(tuple(ls0))
ind0 = ls0.index(0)
if ind0 + 4 < 16:
if ls0[ind0+4] == ind0+5:
ls1 = ls0[:]
ls1[ind0],ls1[ind0+4] = ls1[ind0+4],ls1[ind0]
dfs(ls1)
if ind0 - 4 >= 0:
if ls0[ind0-4] == ind0-3:
ls1 = ls0[:]
ls1[ind0],ls1[ind0-4] = ls1[ind0-4],ls1[ind0]
dfs(ls1)
if ind0 % 4 != 0:
if ls0[ind0-1] == ind0:
ls1 = ls0[:]
ls1[ind0],ls1[ind0-1] = ls1[ind0-1],ls1[ind0]
dfs(ls1)
if ind0 % 4 != 3:
if ls0[ind0+1] == ind0:
ls1 = ls0[:]
ls1[ind0],ls1[ind0+1] = ls1[ind0+1],ls1[ind0]
dfs(ls1)
dfs(kls)
print('Yes' if ls in als else 'No')