結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー convexineqconvexineq
提出日時 2020-12-29 07:10:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 568 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 71,912 KB
最終ジャッジ日時 2024-04-15 06:22:09
合計ジャッジ時間 2,039 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
69,620 KB
testcase_01 AC 38 ms
52,132 KB
testcase_02 AC 58 ms
67,416 KB
testcase_03 AC 60 ms
69,676 KB
testcase_04 AC 52 ms
66,780 KB
testcase_05 AC 35 ms
52,408 KB
testcase_06 AC 59 ms
70,956 KB
testcase_07 AC 37 ms
53,092 KB
testcase_08 AC 61 ms
71,912 KB
testcase_09 AC 40 ms
53,944 KB
testcase_10 AC 55 ms
67,644 KB
testcase_11 AC 41 ms
60,260 KB
testcase_12 AC 60 ms
69,612 KB
testcase_13 AC 57 ms
70,832 KB
testcase_14 AC 57 ms
70,312 KB
testcase_15 AC 58 ms
70,312 KB
testcase_16 AC 56 ms
70,148 KB
testcase_17 AC 56 ms
70,592 KB
testcase_18 AC 55 ms
69,936 KB
testcase_19 AC 60 ms
71,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dfs(x,y):
    if all(a[i] == goal[i] for i in range(4)): return True
    for nx,ny in [(x-1,y),(x+1,y),(x,y+1),(x,y-1)]:
        if 0 <= nx < 4 and 0 <= ny < 4 and used[a[nx][ny]] == 0:
            c = a[nx][ny]
            used[c] = 1
            a[x][y], a[nx][ny] = c, 0
            if dfs(nx,ny): return True
            a[x][y], a[nx][ny] = 0, c
            used[c] = 0
    return False

used = [0]*16
goal = [list(map(int,input().split())) for _ in range(4)]
a = [list(range(4*i+1,4*(i+1)+1)) for i in range(4)]
a[3][3] = 0
print("Yes" if dfs(3,3) else "No")
0