結果

問題 No.307 最近色塗る問題多くない?
ユーザー Cos5XCos5X
提出日時 2015-11-27 23:55:38
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 885 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 11,416 KB
実行使用メモリ 34,340 KB
最終ジャッジ日時 2023-10-12 01:43:44
合計ジャッジ時間 6,725 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
19,548 KB
testcase_01 AC 82 ms
15,044 KB
testcase_02 AC 82 ms
15,132 KB
testcase_03 AC 83 ms
15,144 KB
testcase_04 AC 235 ms
18,784 KB
testcase_05 AC 86 ms
15,188 KB
testcase_06 AC 89 ms
15,312 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w = gets.split(' ').map(&:to_i)
map = []

h.times do
  map.push(gets.split(' ').map(&:to_i))
end

queue = []
gets.to_i.times do
  hh, ww, n = gets.split(' ').map(&:to_i)
  hh -= 1
  ww -= 1
  c = map[hh][ww]
  map[hh][ww] = n
  next if c == n

  queue.push([hh-1, ww]) if hh > 0 and map[hh-1][ww] == c
  queue.push([hh+1, ww]) if hh < h-1 and map[hh+1][ww] == c
  queue.push([hh, ww-1]) if ww > 0 and map[hh][ww-1] == c
  queue.push([hh, ww+1]) if ww < w-1 and map[hh][ww+1] == c
  while queue.empty?.! do
    hhh, www = queue.pop
    map[hhh][www] = n
    queue.push([hhh-1, www]) if hhh > 0 and map[hhh-1][www] == c
    queue.push([hhh+1, www]) if hhh < h-1 and map[hhh+1][www] == c
    queue.push([hhh, www-1]) if www > 0 and map[hhh][www-1] == c
    queue.push([hhh, www+1]) if www < w-1 and map[hhh][www+1] == c
    queue.uniq!
  end
end

map.each do |m|
  puts m.join(' ')
end
0