# AtCoder Beginner Contest 064

URL: https://atcoder.jp/contests/abc064 (opens new window)

# A

r,g,b = gets.chomp.split(" ").map(&:to_i)
# r * 100 は明らかに4の倍数なのでg,bだけで良い
puts (g * 10 + b) % 4 == 0 ? "YES" : "NO"

# B

n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)
puts arr.max - arr.min

# C

色が最大8種類と勝手に解釈してしまってなかなか解けなかった...

n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)

# 0: 灰の人数, 1: 茶の人数, ...
count_arr = Array.new(8, 0)
free = 0

arr.each do |a|
  if a >= 3200
    free += 1
  else
    count_arr[a / 400] += 1
  end
end

pos_count = 0
count_arr.each do |count|
  pos_count += 1 if count > 0
end

min = [pos_count, 1].max
max = pos_count + free
puts "#{min} #{max}"

# D

n = gets.chomp.to_i
s = gets.chomp

left = ""
right = ""

left_count = 0
s.each_char do |c|
  if c == "("
    left_count += 1
  else # ")"
    if left_count <= 0
      left += "("
    else
      left_count -= 1
    end
  end
end

if left_count > 0
  right = ")" * left_count
end

puts left + s + right
Last Updated: 2020/08/15 20:23