結果
問題 |
No.228 ゆきこちゃんの 15 パズル
|
ユーザー |
|
提出日時 | 2017-05-24 23:38:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,332 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 78,124 KB |
最終ジャッジ日時 | 2024-09-19 18:38:55 |
合計ジャッジ時間 | 2,853 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | AC * 9 WA * 8 |
ソースコード
import sys import copy goal = list(map(lambda e:e%16, range(1,17))) def yes(): print("YES") sys.exit() def dfs(a, moved,dep=0): # print(dep,a,moved) if a == goal: yes() idx = a.index(0) x = idx%4 y = idx/4 if 0<x and not moved[a[idx-1]]: moved[a[idx-1]] = 1 a[idx-1], a[idx] = a[idx], a[idx-1] dfs(copy.copy(a), copy.copy(moved), dep+1) a[idx-1], a[idx] = a[idx], a[idx-1] moved[a[idx-1]] = 0 if x<3 and not moved[a[idx-1]]: moved[a[idx+1]] = 1 a[idx+1], a[idx] = a[idx], a[idx+1] dfs(copy.copy(a), copy.copy(moved), dep+1) a[idx+1], a[idx] = a[idx], a[idx+1] moved[a[idx+1]] = 0 if 0<y and not moved[a[idx-4]]: moved[a[idx-4]] = 1 a[idx-4], a[idx] = a[idx], a[idx-4] dfs(copy.copy(a), copy.copy(moved), dep+1) a[idx-4], a[idx] = a[idx], a[idx-4] moved[a[idx-4]] = 0 if y<3 and not moved[a[idx+4]]: moved[a[idx+4]] = 1 a[idx+4], a[idx] = a[idx], a[idx+4] dfs(copy.copy(a), copy.copy(moved), dep+1) a[idx+4], a[idx] = a[idx], a[idx+4] moved[a[idx+4]] = 0 x = list(map(int,input().split())) x+= list(map(int,input().split())) x+= list(map(int,input().split())) x+= list(map(int,input().split())) dfs(x,[0]*16) print("No")