結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー roiti46
提出日時 2016-10-10 21:01:22
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 656 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-11-22 01:05:53
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

r = {i + 1:(i%4, i/4) for i in xrange(15)}
a = [map(int, raw_input().split()) for i in xrange(4)]

for y in xrange(4):
    for x in xrange(4):
        if a[y][x] == 0: continue
        xx, yy = r[a[y][x]]
        if abs(xx - x) + abs(yy - y) > 1:
            print "No"
            exit()
t = 0
for i in xrange(16):
    if a[i/4][i%4] == 0:
        t += abs(3 - i%4) + abs(3 - i/4)
        continue
    for j in xrange(i + 1, 16):
        if a[j/4][j%4] == 0: continue
        if a[i/4][i%4] > a[j/4][j%4]: t += 1
print "Yes" if t%2 == 0 else "No"
0