Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created February 18, 2018 15:30
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/47b8ef9500a89c4fdb13b7553b3ce0b9 to your computer and use it in GitHub Desktop.
Save whatalnk/47b8ef9500a89c4fdb13b7553b3ce0b9 to your computer and use it in GitHub Desktop.
Hack to the Future 2018 Qual
n = 100
a = []
100.times do
r = gets.chomp.split(" ").map(&:to_i)
a += r
end
ret = []
1000.times do
amax = a.max
h = [n, amax].min
break if h == 0
i = a.index(amax)
y = i / n
x = i - (n * y)
n.times do |yy|
n.times do |xx|
a[yy * n + xx] -= [0, h - (xx - x).abs - (yy - y).abs].max
end
end
ret << "#{x} #{y} #{h}"
end
puts ret.size
ret.each do |l|
puts l
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment