結果

問題 No.323 yuki国
ユーザー kura07kura07
提出日時 2015-12-16 23:48:01
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,763 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 11,192 KB
実行使用メモリ 15,824 KB
最終ジャッジ日時 2023-10-14 11:24:26
合計ジャッジ時間 5,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,256 KB
testcase_01 AC 75 ms
15,128 KB
testcase_02 AC 77 ms
15,116 KB
testcase_03 AC 77 ms
15,316 KB
testcase_04 AC 76 ms
15,108 KB
testcase_05 AC 75 ms
15,004 KB
testcase_06 AC 76 ms
15,172 KB
testcase_07 AC 75 ms
15,180 KB
testcase_08 AC 75 ms
15,124 KB
testcase_09 AC 86 ms
15,416 KB
testcase_10 AC 76 ms
14,996 KB
testcase_11 AC 76 ms
15,288 KB
testcase_12 AC 77 ms
15,148 KB
testcase_13 AC 86 ms
15,620 KB
testcase_14 AC 76 ms
15,216 KB
testcase_15 AC 85 ms
15,316 KB
testcase_16 AC 96 ms
15,824 KB
testcase_17 AC 82 ms
15,456 KB
testcase_18 AC 81 ms
15,144 KB
testcase_19 AC 76 ms
15,176 KB
testcase_20 AC 91 ms
15,472 KB
testcase_21 AC 77 ms
15,080 KB
testcase_22 AC 85 ms
15,484 KB
testcase_23 AC 77 ms
15,128 KB
testcase_24 AC 84 ms
15,564 KB
testcase_25 AC 75 ms
15,004 KB
testcase_26 AC 85 ms
15,436 KB
testcase_27 AC 76 ms
15,304 KB
testcase_28 AC 93 ms
15,544 KB
testcase_29 AC 93 ms
15,544 KB
testcase_30 WA -
testcase_31 AC 75 ms
15,128 KB
testcase_32 WA -
testcase_33 AC 77 ms
15,272 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 77 ms
15,076 KB
testcase_37 AC 78 ms
15,220 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
			if new_last < 1
				new_first = new_last = 0
			elsif new_first < 1
				new_first = other.range.first.even? ? 1 : 2
			end
			@range = new_first..new_last
		else
			new_first = [@range.first, other.range.first + @yuki].min
			new_last = [@range.last, other.range.last + @yuki].max
			if new_last < 1
				new_first = new_last = 0
			elsif new_first < 1 || new_first < @range.first
				new_first = other.range.first.even? ? 1 : 2
			end
			new_last = Float::INFINITY if @range.last < new_last
			@range = new_first..new_last
		end
		return (original_range && original_range != @range) ||
			(original_range.nil? && @range != (0..0))
	end

	def to_s
		@range.nil? ?
			"___" :
			"#{@range.first}-#{@range.last==Float::INFINITY ? ?X : @range.last}"
	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]]

cnt = 0
while stack.size > 0
	cnt+=1
	i, j = stack.pop
	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 map.map{|a| a*?, }
		puts 'Yes'
		exit
	end
end

#puts map.map{|a| a*?, }
#puts map.map{|a| a.map{|d| d.yuki>0 ? ?o : ?_ }*"" }
puts 'No'
0