結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー cielciel
提出日時 2016-02-28 00:16:19
言語 Ruby
(3.3.0)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 15,288 KB
最終ジャッジ日時 2023-08-27 01:33:28
合計ジャッジ時間 3,071 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,040 KB
testcase_01 AC 85 ms
15,288 KB
testcase_02 AC 86 ms
15,040 KB
testcase_03 AC 85 ms
15,124 KB
testcase_04 AC 87 ms
15,144 KB
testcase_05 AC 85 ms
15,148 KB
testcase_06 AC 86 ms
15,040 KB
testcase_07 AC 84 ms
15,152 KB
testcase_08 AC 85 ms
15,240 KB
testcase_09 AC 85 ms
15,212 KB
testcase_10 AC 84 ms
15,240 KB
testcase_11 AC 84 ms
15,240 KB
testcase_12 AC 87 ms
15,148 KB
testcase_13 AC 83 ms
15,200 KB
testcase_14 AC 83 ms
15,064 KB
testcase_15 AC 83 ms
15,040 KB
testcase_16 AC 82 ms
15,244 KB
testcase_17 AC 84 ms
15,248 KB
testcase_18 AC 83 ms
15,152 KB
testcase_19 AC 83 ms
15,248 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
def perm
	r=0
	A.size.times{|i|
		(i+1..A.size-1).each{|j|
			r+=1 if A[i]>A[j]
		}
	}
	r
end
a=$<.map{|e|e.split.map(&:to_i)}
A=[]
ds=0
d0=0
parity=nil
4.times{|y|4.times{|x|
	k=a[y][x]
	if k>0
		A<<k
		k-=1
		ty,tx=k.divmod(4)
		d=(y-ty).abs+(x-tx).abs
		ds+=d
		if d>1
			puts :No
			exit
		end
	else
		tx=ty=3
		parity=(y-ty).abs
		d0=(y-ty).abs+(x-tx).abs
	end
}}
if (ds==0)!=(d0==0)
	puts :No
	exit
end
puts [:Yes,:No][(perm+parity)%2]
0