Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active October 15, 2017 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/91849d18a5ba07371d5b433e21a1f354 to your computer and use it in GitHub Desktop.
Save whatalnk/91849d18a5ba07371d5b433e21a1f354 to your computer and use it in GitHub Desktop.
AtCoder ARC #041 B - アメーバ
# Editorial ver.
N, M = gets.chomp.split(" ").map(&:to_i)
@m = []
N.times do
@m << gets.chomp.split("").map(&:to_i)
end
@ans = Array.new(N){Array.new(M, 0)}
(N-2).times do |i|
(1...(M-1)).each do |j|
x = @m[i][j]
@ans[i+1][j] += x
@m[i][j] -= x
@m[i+1][j-1] -= x
@m[i+1][j+1] -= x
@m[i+2][j] -= x
end
end
@ans.each do |row|
puts row.join("")
end
N, M = gets.chomp.split(" ").map(&:to_i)
@m = []
N.times do
@m << gets.chomp.split("").map(&:to_i)
end
@ans = Array.new(N){Array.new(M, 0)}
(1...(N-1)).each do |i|
(1...(M-1)).each do |j|
x = [@m[i-1][j], @m[i][j+1], @m[i+1][j], @m[i][j-1]].min
@ans[i][j] = x
@m[i-1][j] -= x
@m[i][j+1] -= x
@m[i+1][j] -= x
@m[i][j-1] -= x
end
end
@ans.each do |row|
puts row.join("")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment