Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created September 9, 2018 05:56
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/ebc3e8554d01f3fb89139406b2c7f11f to your computer and use it in GitHub Desktop.
Save whatalnk/ebc3e8554d01f3fb89139406b2c7f11f to your computer and use it in GitHub Desktop.
AtCoder ABC #109 D
h, w = gets.chomp.split(" ").map(&:to_i)
a = []
h.times do
a << gets.chomp.split(" ").map(&:to_i)
end
ans = []
h.times do |i|
w.times do |j|
if (a[i][j]).odd?
if j < w - 1
a[i][j] -= 1
a[i][j+1] += 1
ans << [i+1, j+1, i+1, j+2]
else
if i < h - 1
a[i][j] -= 1
a[i+1][j] += 1
ans << [i+1, j+1, i+2, j+1]
end
end
end
end
end
puts ans.length
ans.each{|line| puts line.join(" ")}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment