結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー nisizawanisizawa
提出日時 2017-12-05 14:12:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-06 10:32:11
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def around(pos):
    ls = []
    #上
    if pos >= 4:
        ls.append(pos - 4)
    #下
    if pos <= 11:
        ls.append(pos + 4)
    #左
    if pos % 4 != 0:
        ls.append(pos - 1)
    #右
    if pos % 4 != 3:
        ls.append(pos + 1)
    return ls

def check(ls):
    pos = ls.index('0')
    g = goal[pos]
    
    for p in around(pos):
        if ls[p] == g:
            ls[p], ls[pos] = ls[pos], ls[p]
            return True
    return False
    
a = input().split()
b = input().split()
c = input().split()
d = input().split()
ls = a + b + c + d

goal = [str((i + 1) % 16) for i in range(16)]

while True:
    if ls == goal:
        print('YES')
        break
    if not check(ls):
        print('NO')
        break
0