結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー しらっ亭
提出日時 2015-07-09 00:33:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-08 01:45:17
合計ジャッジ時間 1,484 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def check(B):
    return all(B[i] == i for i in range(16))

def solve(B):
    z = B.index(0)
    B[z] = 16
    B = [n - 1 for n in B]

    while not check(B):
        if z > 3:
            if B[z - 4] == z:
                B[z], B[z - 4] = B[z - 4], B[z]
                z -= 4
                continue
        if z % 4 != 0:
            if B[z - 1] == z:
                B[z], B[z - 1] = B[z - 1], B[z]
                z -= 1
                continue
        if z % 4 != 3:
            if B[z + 1] == z:
                B[z], B[z + 1] = B[z + 1], B[z]
                z += 1
                continue
        if z < 12:
            if B[z + 4] == z:
                B[z], B[z + 4] = B[z + 4], B[z]
                z += 4
                continue

        print('No')
        return
    print('Yes')


def main():
    A = []
    for i in range(4):
        A.extend(list(map(int, input().split())))
    solve(A)


if __name__ == '__main__':
    main()
0