結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー lloyzlloyz
提出日時 2023-04-09 02:41:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 710 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 53,552 KB
最終ジャッジ日時 2024-04-14 21:19:01
合計ジャッジ時間 2,202 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,112 KB
testcase_01 AC 38 ms
53,316 KB
testcase_02 AC 38 ms
52,952 KB
testcase_03 AC 37 ms
52,136 KB
testcase_04 AC 36 ms
53,060 KB
testcase_05 AC 38 ms
52,488 KB
testcase_06 AC 40 ms
53,288 KB
testcase_07 AC 37 ms
53,008 KB
testcase_08 AC 36 ms
52,872 KB
testcase_09 AC 36 ms
52,872 KB
testcase_10 AC 36 ms
52,752 KB
testcase_11 AC 37 ms
52,504 KB
testcase_12 AC 37 ms
52,632 KB
testcase_13 AC 36 ms
53,140 KB
testcase_14 AC 37 ms
52,496 KB
testcase_15 AC 37 ms
52,672 KB
testcase_16 AC 38 ms
52,024 KB
testcase_17 AC 36 ms
53,216 KB
testcase_18 AC 37 ms
52,896 KB
testcase_19 AC 38 ms
53,552 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