結果

問題 No.424 立体迷路
ユーザー cielciel
提出日時 2016-09-24 17:28:59
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-29 07:29:41
合計ジャッジ時間 3,549 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,032 KB
testcase_01 WA -
testcase_02 AC 88 ms
12,160 KB
testcase_03 WA -
testcase_04 AC 82 ms
12,160 KB
testcase_05 WA -
testcase_06 AC 87 ms
12,160 KB
testcase_07 WA -
testcase_08 AC 86 ms
12,160 KB
testcase_09 WA -
testcase_10 AC 89 ms
12,288 KB
testcase_11 WA -
testcase_12 AC 83 ms
12,288 KB
testcase_13 WA -
testcase_14 AC 92 ms
12,288 KB
testcase_15 WA -
testcase_16 AC 84 ms
12,288 KB
testcase_17 AC 104 ms
12,288 KB
testcase_18 WA -
testcase_19 AC 104 ms
12,544 KB
testcase_20 WA -
testcase_21 AC 87 ms
12,416 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 107 ms
12,800 KB
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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{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