# AtCoder Regular Contest 041

URL: https://atcoder.jp/contests/arc041/ (opens new window)

# B

n,m = gets.chomp.split(" ").map(&:to_i)
arr = n.times.map{gets.chomp.split("").map(&:to_i)}

result = []
n.times do
  result << Array.new(m, 0)
end

1.upto(n-2) do |i|
  1.upto(m-2) do |j|
    # 四方の最小値が(i, j)にもともといたアメーバの数
    min = [arr[i-1][j], arr[i+1][j], arr[i][j-1], arr[i][j+1]].min
    result[i][j] = min
    arr[i-1][j] -= min
    arr[i+1][j] -= min
    arr[i][j-1] -= min
    arr[i][j+1] -= min
  end
end

result.each do |row|
  puts row.join("")
end
Last Updated: 2020/08/15 20:23