Last active
October 15, 2017 07:59
-
-
Save whatalnk/91849d18a5ba07371d5b433e21a1f354 to your computer and use it in GitHub Desktop.
AtCoder ARC #041 B - アメーバ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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