結果
問題 |
No.228 ゆきこちゃんの 15 パズル
|
ユーザー |
|
提出日時 | 2022-01-05 21:21:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 53 ms / 5,000 ms |
コード長 | 923 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,296 KB |
実行使用メモリ | 66,036 KB |
最終ジャッジ日時 | 2024-11-06 08:37:13 |
合計ジャッジ時間 | 1,982 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
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+2: ls1 = ls0[:] ls1[ind0],ls1[ind0+1] = ls1[ind0+1],ls1[ind0] dfs(ls1) dfs(kls) print('Yes' if ls in als else 'No')