Created
July 31, 2016 23:24
-
-
Save whatalnk/7be0431e07e036534ee68910c43f3fee to your computer and use it in GitHub Desktop.
AtCoder AGC #002 [Ruby]
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
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 |
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) | |
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