結果

問題 No.424 立体迷路
ユーザー cielciel
提出日時 2016-09-24 17:32:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 593 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 11,260 KB
実行使用メモリ 15,492 KB
最終ジャッジ日時 2023-09-18 16:54:57
合計ジャッジ時間 3,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,324 KB
testcase_01 AC 83 ms
15,148 KB
testcase_02 AC 84 ms
15,176 KB
testcase_03 AC 85 ms
15,328 KB
testcase_04 AC 87 ms
15,332 KB
testcase_05 AC 85 ms
15,188 KB
testcase_06 AC 85 ms
15,172 KB
testcase_07 AC 83 ms
15,152 KB
testcase_08 AC 86 ms
15,316 KB
testcase_09 AC 85 ms
15,140 KB
testcase_10 AC 84 ms
15,244 KB
testcase_11 AC 85 ms
15,284 KB
testcase_12 AC 84 ms
15,164 KB
testcase_13 AC 84 ms
15,248 KB
testcase_14 AC 84 ms
15,172 KB
testcase_15 AC 84 ms
15,140 KB
testcase_16 AC 84 ms
15,172 KB
testcase_17 AC 86 ms
15,296 KB
testcase_18 AC 86 ms
15,296 KB
testcase_19 AC 86 ms
15,204 KB
testcase_20 AC 87 ms
15,376 KB
testcase_21 AC 86 ms
15,260 KB
testcase_22 AC 85 ms
15,176 KB
testcase_23 AC 85 ms
15,296 KB
testcase_24 AC 102 ms
15,356 KB
testcase_25 AC 102 ms
15,492 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
h,w=gets.split.map(&:to_i)
sy,sx,gy,gx=gets.split.map{|e|e.to_i-1}
m=h.times.map{gets.chomp.chars.map(&:to_i)}
d={[sx,sy]=>0}
q=[[sx,sy]]
while !q.empty?
	x,y=q.shift
	[[-1,0],[0,-1],[1,0],[0,1]].each{|x0,y0|
		if 0<=x+x0&&x+x0<w && 0<=y+y0&&y+y0<h && (m[y][x]-m[y+y0][x+x0]).abs<=1 && !d[[x+x0,y+y0]]
			d[[x+x0,y+y0]]=d[[x,y]]+1
			q<<[x+x0,y+y0]
		end
		if 0<=x+x0*2&&x+x0*2<w && 0<=y+y0*2&&y+y0*2<h && m[y][x]>m[y+y0][x+x0] && m[y][x]==m[y+y0*2][x+x0*2] && !d[[x+x0*2,y+y0*2]]
			d[[x+x0*2,y+y0*2]]=d[[x,y]]+1
			q<<[x+x0*2,y+y0*2]
		end
	}
end
puts d[[gx,gy]] ? :YES : :NO
0