Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created July 31, 2016 23:24
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/7be0431e07e036534ee68910c43f3fee to your computer and use it in GitHub Desktop.
Save whatalnk/7be0431e07e036534ee68910c43f3fee to your computer and use it in GitHub Desktop.
AtCoder AGC #002 [Ruby]
a, b = gets.chomp.split(" ").map(&:to_i)
if a > 0 then
puts "Positive"
elsif a < 0 && b >= 0 then
puts "Zero"
elsif (b - a + 1).even? then
puts "Positive"
else
puts "Negative"
end
n, m = gets.chomp.split(" ").map(&:to_i)
box = Struct.new("Box", :red, :n)
boxes = Array.new(n+1){box.new(false, 1)}
boxes[1][:red] = true
m.times do
x, y = gets.chomp.split(" ").map(&:to_i)
if boxes[x][:red] then
boxes[y][:red] = true
end
boxes[x][:n] = boxes[x][:n] - 1
if boxes[x][:n] == 0 then
boxes[x][:red] = false
end
boxes[y][:n] = boxes[y][:n] + 1
end
res = 0
boxes.each do |bx|
res += 1 if bx[:red] && (bx[:n] != 0)
end
puts res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment