Create a gist now

Instantly share code, notes, and snippets.

Codeforces Round #340 Div2
n = gets.chomp.to_i
a = n / 5
b = n % 5
if b == 0 then
puts a
else
puts a + 1
end
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
nut = []
a.each_with_index do |i, j|
if i == 1 then
nut << j
end
end
dnut = []
(1..(nut.length - 1)).each do |i|
dnut << nut[i] - nut[i - 1]
end
if a.all?{|v| v == 0} then
puts 0
elsif dnut.empty? then
puts 1
else
puts dnut.inject(:*)
end
n, x1, y1, x2, y2 = gets.chomp.split(" ").map(&:to_i)
dist = []
n.times do
fx, fy = gets.chomp.split(" ").map(&:to_i)
d1 = (x1 - fx)**2 + (y1 - fy)**2
d2 = (x2 - fx)**2 + (y2 - fy)**2
dist << [d1, d2]
end
dist << [0,0]
res = Float::INFINITY
dist.each do |i|
r1 = i[0]
r2 = 0
dist.each do |j|
if j[0] > r1 then
r2 = [r2, j[1]].max
end
end
res = [res, r1 + r2].min
end
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment