結果

問題 No.367 ナイトの転身
ユーザー cielciel
提出日時 2017-10-29 21:54:17
言語 Crystal
(1.11.2)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 17,822 ms
コンパイル使用メモリ 257,352 KB
実行使用メモリ 32,920 KB
最終ジャッジ日時 2023-09-13 09:26:16
合計ジャッジ時間 18,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,460 KB
testcase_02 AC 2 ms
4,428 KB
testcase_03 AC 3 ms
4,420 KB
testcase_04 AC 2 ms
4,484 KB
testcase_05 AC 3 ms
4,388 KB
testcase_06 AC 2 ms
4,560 KB
testcase_07 AC 3 ms
4,516 KB
testcase_08 AC 2 ms
4,396 KB
testcase_09 AC 2 ms
4,508 KB
testcase_10 AC 131 ms
18,408 KB
testcase_11 AC 236 ms
32,920 KB
testcase_12 AC 13 ms
5,940 KB
testcase_13 AC 19 ms
7,272 KB
testcase_14 AC 50 ms
11,016 KB
testcase_15 AC 3 ms
4,648 KB
testcase_16 AC 50 ms
10,748 KB
testcase_17 AC 9 ms
5,616 KB
testcase_18 AC 12 ms
5,808 KB
testcase_19 AC 11 ms
5,828 KB
testcase_20 AC 4 ms
4,704 KB
testcase_21 AC 11 ms
5,832 KB
testcase_22 AC 3 ms
4,608 KB
testcase_23 AC 2 ms
4,628 KB
testcase_24 AC 3 ms
4,588 KB
testcase_25 AC 3 ms
4,720 KB
testcase_26 AC 3 ms
4,500 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)
g=q=[] of Tuple(Int32,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,1}])};m<<s}
d={q[0]=>0}
while !q.empty?
	c,cx,cy=q.shift
	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[{c,cx,cy}]+1
				q<<z
				if {nx,ny,1}==g[0]
					p d[z];exit
				end
			end
		end
	}
end
p -1
0