結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー lloyzlloyz
提出日時 2023-04-09 02:41:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-14 21:19:08
合計ジャッジ時間 1,623 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 30 ms
10,752 KB
testcase_06 AC 29 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 29 ms
10,752 KB
testcase_09 AC 29 ms
10,752 KB
testcase_10 AC 29 ms
10,752 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 36 ms
10,752 KB
testcase_14 AC 29 ms
10,752 KB
testcase_15 AC 30 ms
10,880 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 31 ms
10,752 KB
testcase_18 AC 30 ms
10,752 KB
testcase_19 AC 30 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

A = [list(map(int, input().split())) for _ in range(4)]

zero_i = -1
correct_pos_set = set()
for i in range(4):
    for j in range(4):
        if A[i][j] == 0:
            zero_i = 4 * i + j
        if A[i][j] == 4 * i + j + 1:
            correct_pos_set.add(4 * i + j)

all_correct_set = set(list(range(15)))
Directions = [1, -1, 4, -4]
while correct_pos_set != all_correct_set:
    flag = False
    for di in Directions:
        ni = zero_i + di
        if 0 <= ni < 16:
            if A[ni // 4][ni % 4] == zero_i + 1:
                correct_pos_set.add(zero_i)
                zero_i = ni
                flag = True
                break
    if not flag:
        print("No")
        exit()
print("Yes")
0