結果

問題 No.424 立体迷路
ユーザー urutomurutom
提出日時 2017-04-17 17:27:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 11,464 KB
実行使用メモリ 15,544 KB
最終ジャッジ日時 2023-09-18 17:01:08
合計ジャッジ時間 3,644 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,140 KB
testcase_01 AC 82 ms
15,256 KB
testcase_02 AC 79 ms
15,140 KB
testcase_03 AC 81 ms
15,096 KB
testcase_04 AC 86 ms
15,168 KB
testcase_05 AC 81 ms
15,268 KB
testcase_06 AC 81 ms
15,264 KB
testcase_07 AC 80 ms
15,308 KB
testcase_08 AC 82 ms
15,112 KB
testcase_09 AC 83 ms
15,168 KB
testcase_10 AC 81 ms
15,108 KB
testcase_11 AC 81 ms
15,024 KB
testcase_12 AC 81 ms
15,160 KB
testcase_13 AC 82 ms
15,172 KB
testcase_14 AC 81 ms
15,112 KB
testcase_15 AC 82 ms
15,164 KB
testcase_16 AC 81 ms
15,304 KB
testcase_17 AC 81 ms
15,088 KB
testcase_18 AC 82 ms
15,300 KB
testcase_19 AC 81 ms
15,032 KB
testcase_20 AC 81 ms
15,120 KB
testcase_21 AC 81 ms
15,212 KB
testcase_22 AC 83 ms
15,116 KB
testcase_23 AC 80 ms
15,264 KB
testcase_24 AC 112 ms
15,544 KB
testcase_25 AC 113 ms
15,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h,w=gets.split.map(&:to_i)
sx,sy,gx,gy=gets.split.map{|s|s.to_i-1}
maze=h.times.map{gets.chomp.bytes.to_a}

init_state=[sx,sy]
q=[init_state]
visited={}

until q.empty?
	curr_state=q.shift
	next if visited[curr_state]
	visited[curr_state]=true
	if curr_state==[gx,gy]
		puts "YES"
		exit
	end
	height=maze.dig(*curr_state)
	x,y=curr_state

	[[1,0],[0,1],[-1,0],[0,-1]].each{|dx,dy|
		nx,ny=x+dx,y+dy
		next unless (0...h)===nx
		next unless (0...w)===ny
		next_state=[nx,ny]
		next if (maze.dig(*next_state)-height).abs>1
		q.push next_state
	}

	[[2,0],[0,2],[-2,0],[0,-2]].each{|dx,dy|
		nx,ny=x+dx,y+dy
		next unless (0...h)===nx
		next unless (0...w)===ny
		next_state=[nx,ny]
		next unless maze.dig(*next_state)==height
		middle=[x+dx/2,y+dy/2]
		next if maze.dig(*middle)>=height
		q.push next_state
	}	
end

puts "NO"
0