結果

問題 No.323 yuki国
ユーザー kura07kura07
提出日時 2015-12-27 10:33:28
言語 Ruby
(3.3.0)
結果
AC  
実行時間 156 ms / 5,000 ms
コード長 1,383 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 11,212 KB
実行使用メモリ 15,824 KB
最終ジャッジ日時 2023-09-10 21:25:05
合計ジャッジ時間 5,407 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,292 KB
testcase_01 AC 81 ms
15,012 KB
testcase_02 AC 82 ms
15,192 KB
testcase_03 AC 89 ms
15,208 KB
testcase_04 AC 83 ms
15,188 KB
testcase_05 AC 82 ms
15,204 KB
testcase_06 AC 82 ms
15,040 KB
testcase_07 AC 82 ms
15,144 KB
testcase_08 AC 84 ms
15,244 KB
testcase_09 AC 104 ms
15,508 KB
testcase_10 AC 81 ms
15,240 KB
testcase_11 AC 83 ms
15,140 KB
testcase_12 AC 82 ms
15,204 KB
testcase_13 AC 112 ms
15,572 KB
testcase_14 AC 84 ms
15,284 KB
testcase_15 AC 156 ms
15,824 KB
testcase_16 AC 132 ms
15,688 KB
testcase_17 AC 110 ms
15,556 KB
testcase_18 AC 93 ms
15,428 KB
testcase_19 AC 84 ms
15,312 KB
testcase_20 AC 90 ms
15,308 KB
testcase_21 AC 83 ms
15,036 KB
testcase_22 AC 113 ms
15,492 KB
testcase_23 AC 83 ms
15,144 KB
testcase_24 AC 120 ms
15,680 KB
testcase_25 AC 86 ms
15,152 KB
testcase_26 AC 139 ms
15,632 KB
testcase_27 AC 82 ms
15,364 KB
testcase_28 AC 133 ms
15,636 KB
testcase_29 AC 131 ms
15,592 KB
testcase_30 AC 83 ms
15,152 KB
testcase_31 AC 83 ms
15,328 KB
testcase_32 AC 83 ms
15,100 KB
testcase_33 AC 83 ms
15,120 KB
testcase_34 AC 83 ms
15,232 KB
testcase_35 AC 85 ms
15,008 KB
testcase_36 AC 84 ms
15,360 KB
testcase_37 AC 82 ms
15,128 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Yukidama
	attr_accessor :range
	attr_reader :yuki
	def initialize(range, yuki)
		@range = range
		@yuki = yuki
	end

	def merge!(other)
		original_range = @range

		if @range.nil?
			new_first = other.range.first + @yuki
			new_last = other.range.last + @yuki
		else
			new_first = [@range.first, other.range.first + @yuki].min
			new_last = [@range.last, other.range.last + @yuki].max
		end

		if new_last < 1
			new_first = new_last = 0
		elsif new_first < 1 || [other.yuki,@yuki] == [-1,-1]
			new_first = other.range.first.even? ? 1 : 2
		elsif [other.yuki,@yuki] == [1,1]
			new_last = Float::INFINITY
		end

		@range = new_first..new_last

		return (original_range && original_range != @range) ||
			(original_range.nil? && @range != (0..0))
	end
end

h, w = gets.split.map(&:to_i)
a, si, sj = gets.split.map(&:to_i)
b, gi, gj = gets.split.map(&:to_i)
if (a+si+sj+b+gi+gj).odd?
	puts 'No'
	exit
end
yuki = h.times.map{ gets.chars.map{|c| c==?*?1:-1 } }
map = Array.new(h){|i| Array.new(w){|j| Yukidama.new(nil, yuki[i][j]) } }
map[si][sj].range = a..a
stack = [[si, sj]]

while stack.size > 0
	i, j = stack.shift
	d = map[i][j]
	[[i-1,j],[i+1,j],[i,j-1],[i,j+1]].each{|i,j|
		next unless 0 <= i && i < h && 0 <= j && j < w
		if map[i][j].merge!(d)
			stack.push [i,j]
		end
	}
	if map[gi][gj].range && map[gi][gj].range.include?(b)
		puts 'Yes'
		exit
	end
end

puts 'No'
0