結果
| 問題 | No.228 ゆきこちゃんの 15 パズル | 
| コンテスト | |
| ユーザー |  nisizawa | 
| 提出日時 | 2017-12-05 14:13:10 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 5,000 ms | 
| コード長 | 734 bytes | 
| コンパイル時間 | 94 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 10,752 KB | 
| 最終ジャッジ日時 | 2024-11-28 16:36:59 | 
| 合計ジャッジ時間 | 1,390 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
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
            
            
            
        