結果

問題 No.367 ナイトの転身
ユーザー cielciel
提出日時 2017-10-29 21:56:29
言語 Crystal
(1.11.2)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 17,925 ms
コンパイル使用メモリ 256,848 KB
実行使用メモリ 32,632 KB
最終ジャッジ日時 2023-09-13 09:26:40
合計ジャッジ時間 19,929 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,428 KB
testcase_01 AC 3 ms
4,424 KB
testcase_02 AC 2 ms
4,424 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,508 KB
testcase_05 AC 2 ms
4,472 KB
testcase_06 AC 3 ms
4,496 KB
testcase_07 AC 2 ms
4,408 KB
testcase_08 AC 3 ms
4,472 KB
testcase_09 AC 2 ms
4,432 KB
testcase_10 AC 139 ms
18,492 KB
testcase_11 AC 256 ms
32,632 KB
testcase_12 AC 14 ms
5,948 KB
testcase_13 AC 19 ms
7,464 KB
testcase_14 AC 52 ms
10,620 KB
testcase_15 AC 3 ms
4,584 KB
testcase_16 AC 52 ms
10,872 KB
testcase_17 AC 9 ms
5,688 KB
testcase_18 AC 12 ms
5,764 KB
testcase_19 AC 11 ms
5,768 KB
testcase_20 AC 4 ms
4,752 KB
testcase_21 AC 11 ms
5,724 KB
testcase_22 AC 3 ms
4,508 KB
testcase_23 AC 3 ms
4,520 KB
testcase_24 AC 4 ms
4,768 KB
testcase_25 AC 3 ms
4,680 KB
testcase_26 AC 3 ms
4,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

D=[[{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}],[{-1,-1},{-1,1},{1,-1},{1,1}]]
h,w=gets.not_nil!.split.map(&.to_i)
q=[] of Tuple(Int32,Int32,Int32)
g=Tuple(Int32,Int32)
m=[] of String
h.times{|y|s=gets.not_nil!.chomp;s.size.times{|x|s[x]=='S'&&q<<{0,x,y};s[x]=='G'&&(g={x,y})};m<<s}
d={q[0]=>0}
while !q.empty?
	ck=q.shift
	c,cx,cy=ck
	D[c].each{|(dx,dy)|
		nx,ny=cx+dx,cy+dy
		if 0<=nx&&nx<w && 0<=ny&&ny<h
			nc=c^(m[ny][nx]=='R'?1:0)
			z={nc,nx,ny}
			if !d.has_key?(z)
				d[z]=d[ck]+1
				q<<z
				if {nx,ny}==g
					p d[z];exit
				end
			end
		end
	}
end
p -1
0