結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
![]() |
提出日時 | 2015-11-27 23:53:33 |
言語 | Ruby (3.4.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 869 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 19,740 KB |
最終ジャッジ日時 | 2024-09-14 01:31:59 |
合計ジャッジ時間 | 6,670 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 TLE * 1 -- * 28 |
コンパイルメッセージ
Syntax OK
ソースコード
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 end end map.each do |m| puts m.join(' ') end