結果

問題 No.424 立体迷路
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-17 10:41:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 11,216 KB
実行使用メモリ 15,608 KB
最終ジャッジ日時 2023-09-18 17:03:14
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,176 KB
testcase_01 AC 85 ms
15,300 KB
testcase_02 AC 86 ms
15,116 KB
testcase_03 AC 86 ms
15,124 KB
testcase_04 AC 86 ms
15,100 KB
testcase_05 AC 85 ms
15,080 KB
testcase_06 AC 84 ms
15,248 KB
testcase_07 AC 84 ms
15,324 KB
testcase_08 AC 84 ms
15,248 KB
testcase_09 AC 85 ms
15,320 KB
testcase_10 AC 85 ms
15,324 KB
testcase_11 AC 85 ms
15,132 KB
testcase_12 AC 86 ms
15,076 KB
testcase_13 AC 85 ms
15,248 KB
testcase_14 AC 84 ms
15,040 KB
testcase_15 AC 84 ms
15,176 KB
testcase_16 AC 85 ms
15,152 KB
testcase_17 AC 88 ms
15,156 KB
testcase_18 AC 86 ms
15,456 KB
testcase_19 AC 87 ms
15,220 KB
testcase_20 AC 88 ms
15,400 KB
testcase_21 AC 83 ms
15,244 KB
testcase_22 AC 85 ms
15,364 KB
testcase_23 AC 84 ms
15,188 KB
testcase_24 AC 112 ms
15,552 KB
testcase_25 AC 113 ms
15,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(x,y,h,w)
	return false if x<0 || x>=h || y<0 || y>=w
	return true
end

h,w=gets.split.map{|e| e.to_i}
sx,sy,gx,gy=gets.split.map{|e| e.to_i-1}
m=STDIN.read.split.map{|e|
	e.split("").map{|e2|
		e2.to_i
	}
}
dx=[0,-1,0,1]
dy=[1,0,-1,0]
dx2=[0,-2,0,2]
dy2=[2,0,-2,0]
hs={}
hs[[sx,sy]]=0
dp={}
dp[[sx,sy]]=0
while true
	dp2={}
	dp.keys.each{|e|
		x1=e[0]
		y1=e[1]
		4.times{|i|
			x2=x1+dx[i]
			y2=y1+dy[i]
			if f(x2,y2,h,w)==false
				next
			end
			d=(m[x2][y2]-m[x1][y1]).abs
			add=0
			if d>1
				next
			elsif d==1
				add=1
			end
			e3=[x2,y2]
			k=hs[e]+add
			if hs.key?(e3)==false || hs[e3]>k
				hs[e3]=k
				dp2[e3]=k
			end
		}
		4.times{|i|
			x2=x1+dx2[i]
			y2=y1+dy2[i]
			x3=x1+dx2[i]/2
			y3=y1+dy2[i]/2
			if f(x2,y2,h,w)==false
				next
			end
			d=(m[x2][y2]-m[x1][y1]).abs
			if d!=0
				next
			end
			if m[x3][y3]>=m[x1][y1]
				next
			end
			e3=[x2,y2]
			k=hs[e]+1
			if hs.key?(e3)==false || hs[e3]>k
				hs[e3]=k
				dp2[e3]=k
			end
		}
	}
	break if dp.empty? ==true
	break if dp.key?([gx,gy]) ==true
	dp=dp2
end
if dp.key?([gx,gy])==true
	puts "YES"
else
	puts "NO"
end
0