結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー maimai
提出日時 2017-05-24 23:38:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,332 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 77,604 KB
最終ジャッジ日時 2023-10-19 22:39:56
合計ジャッジ時間 3,421 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
77,144 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 150 ms
77,144 KB
testcase_13 AC 148 ms
77,144 KB
testcase_14 AC 114 ms
76,932 KB
testcase_15 AC 50 ms
61,432 KB
testcase_16 AC 116 ms
76,616 KB
testcase_17 AC 137 ms
77,144 KB
testcase_18 AC 201 ms
77,604 KB
testcase_19 AC 138 ms
77,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")

0