結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-29 21:31:52 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 501 bytes |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 46,592 KB |
| 最終ジャッジ日時 | 2024-11-22 05:35:19 |
| 合計ジャッジ時間 | 13,571 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 TLE * 2 |
コンパイルメッセージ
Main.rb:23: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
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