結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー tnoda_tnoda_
提出日時 2015-08-25 15:00:59
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 6,700 KB
実行使用メモリ 6,056 KB
最終ジャッジ日時 2023-09-25 16:58:54
合計ジャッジ時間 1,449 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,948 KB
testcase_01 AC 11 ms
6,048 KB
testcase_02 AC 11 ms
5,948 KB
testcase_03 AC 11 ms
5,996 KB
testcase_04 AC 12 ms
5,948 KB
testcase_05 AC 12 ms
5,876 KB
testcase_06 AC 12 ms
5,948 KB
testcase_07 AC 11 ms
5,956 KB
testcase_08 AC 11 ms
5,892 KB
testcase_09 AC 12 ms
5,916 KB
testcase_10 AC 11 ms
5,864 KB
testcase_11 AC 11 ms
5,864 KB
testcase_12 AC 11 ms
6,044 KB
testcase_13 AC 11 ms
5,960 KB
testcase_14 AC 11 ms
6,056 KB
testcase_15 AC 11 ms
5,948 KB
testcase_16 AC 11 ms
6,044 KB
testcase_17 AC 11 ms
5,948 KB
testcase_18 AC 11 ms
5,996 KB
testcase_19 AC 10 ms
5,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def move():
    r0, c0 = 0, 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    for i in range(4):
        for j in range(4):
            if A[i][j] == 0:
                r0, c0 = i, j
    for (r, c) in [(r0+dy[i], c0+dx[i])
                   for i in range(4)
                   if 0 <= r0+dy[i] and r0+dy[i] < 4
                   and 0 <= c0+dx[i] and c0+dx[i] < 4]:
        pos = r0 * 4 + c0 + 1
        if A[r][c] == pos:
            A[r][c], A[r0][c0] = 0, pos
            move()

def acceptable():
    for i in range(4):
        for j in range(4):
            if A[i][j] != (i * 4 + j + 1) % 16:
                return "No"
    return "Yes"

A = [map(int, raw_input().split()) for i in range(4)]
r, c = 0, 0
move()
print(acceptable())
0