結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー rlangevinrlangevin
提出日時 2023-01-17 12:36:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 669 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 71,512 KB
最終ジャッジ日時 2023-08-30 17:30:43
合計ジャッジ時間 3,060 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,964 KB
testcase_01 AC 69 ms
70,968 KB
testcase_02 AC 69 ms
70,960 KB
testcase_03 AC 69 ms
71,280 KB
testcase_04 AC 70 ms
71,408 KB
testcase_05 AC 67 ms
71,512 KB
testcase_06 AC 68 ms
71,456 KB
testcase_07 AC 68 ms
71,368 KB
testcase_08 AC 69 ms
71,188 KB
testcase_09 AC 69 ms
70,972 KB
testcase_10 AC 68 ms
71,448 KB
testcase_11 AC 68 ms
70,972 KB
testcase_12 AC 69 ms
71,184 KB
testcase_13 AC 67 ms
71,344 KB
testcase_14 AC 69 ms
71,092 KB
testcase_15 AC 68 ms
71,172 KB
testcase_16 AC 68 ms
71,432 KB
testcase_17 AC 67 ms
71,096 KB
testcase_18 AC 69 ms
71,168 KB
testcase_19 AC 69 ms
70,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(x, y):
    return (4 * x + y + 1)%16

A = []
nx, ny = 0, 0
for i in range(4):
    A.append(list(map(int, input().split())))
    for j in range(4):
        if A[i][j] == 0:
            nx = i
            ny = j

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for _ in range(16):
    for k in range(4):
        x, y = nx + dx[k], ny + dy[k]
        if x < 0 or x > 3 or y < 0 or y > 3:
            continue
        if A[x][y] != f(nx, ny):
            continue
        A[x][y], A[nx][ny] = A[nx][ny], A[x][y]
        nx, ny = x, y
        break

for i in range(4):
    for j in range(4):
        if A[i][j] != f(i, j):
            print("No")
            exit()
print("Yes")
0