結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー roarisroaris
提出日時 2019-08-02 18:54:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 746 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 10,740 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-09-18 18:25:07
合計ジャッジ時間 1,594 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,740 KB
testcase_01 AC 17 ms
7,904 KB
testcase_02 AC 16 ms
7,748 KB
testcase_03 AC 16 ms
7,808 KB
testcase_04 AC 16 ms
7,788 KB
testcase_05 AC 16 ms
7,912 KB
testcase_06 AC 17 ms
7,740 KB
testcase_07 AC 17 ms
7,740 KB
testcase_08 AC 16 ms
7,844 KB
testcase_09 AC 17 ms
7,900 KB
testcase_10 AC 16 ms
7,900 KB
testcase_11 AC 16 ms
7,844 KB
testcase_12 AC 16 ms
7,720 KB
testcase_13 AC 16 ms
7,736 KB
testcase_14 AC 16 ms
7,852 KB
testcase_15 AC 16 ms
7,816 KB
testcase_16 AC 16 ms
7,792 KB
testcase_17 AC 16 ms
7,840 KB
testcase_18 AC 16 ms
7,724 KB
testcase_19 AC 16 ms
7,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#シミュレーション
a = [list(map(int, input().split())) for _ in range(4)]
goal = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]]
locked = [None] + [False] * 15

while True:
    if a == goal:
        print('Yes')
        break
        
    for i in range(4):
        for j in range(4):
            if a[i][j] == 0:
                mx, my = i, j
                break
    
    for nx, ny in [(mx+1, my), (mx-1, my), (mx, my+1), (mx, my-1)]:
        if 0 <= nx <= 3 and 0 <= ny <= 3:
            if a[nx][ny] == goal[mx][my] and not locked[a[nx][ny]]:
                locked[a[nx][ny]] = True
                a[mx][my] = a[nx][ny]
                a[nx][ny] = 0
                break
    else:
        print('No')
        break
0