結果

問題 No.367 ナイトの転身
ユーザー cielciel
提出日時 2017-10-29 21:31:52
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 501 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 39,180 KB
最終ジャッジ日時 2024-05-01 22:23:04
合計ジャッジ時間 5,117 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
17,536 KB
testcase_01 AC 96 ms
12,288 KB
testcase_02 AC 91 ms
12,160 KB
testcase_03 AC 91 ms
12,288 KB
testcase_04 AC 92 ms
12,160 KB
testcase_05 AC 96 ms
12,160 KB
testcase_06 AC 97 ms
12,160 KB
testcase_07 AC 91 ms
12,160 KB
testcase_08 AC 103 ms
12,160 KB
testcase_09 AC 91 ms
12,288 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:23: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

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.split.map(&:to_i)
g=q=[]
m=$<.map.with_index{|e,y|s=e.chomp;s.each_char.with_index{|c,x|q<<[0,x,y]if c=='S';g=[x,y]if c=='G'}}
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[z]
				d[z]=d[[c,cx,cy]]+1
				q<<z
				if [nx,ny]==g
					p d[z];exit
				end
			end
		end
	}
end
p -1
0