ABC165
https://atcoder.jp/contests/abc165
30分くらい時間が経ってから始めた。A, B, C 3完。
A: We Love Golf
gets.to_i a, b = gets.split.map(&:to_i) if (a % k).zero? puts "OK" else i = (a / k + 1) * k puts i <= b ? "OK" : "NG" end
B: 1%
x = gets.to_i y = 1 tmp = 100 loop do tmp = (tmp * 1.01).to_i break if tmp >= x y += 1 end puts y
C: Many Requirements
n, m, q = gets.split.map(&:to_i) set = q.times.map {gets.split.map(&:to_i)} maximum = 0 [*1..m].repeated_combination(n) do |seq| score = 0 set.each do |a, b, c, d| score += d if seq[b - 1] - seq[a - 1] == c end maximum = [maximum, score].max end puts maximum
遅くなるけれどこうも書ける。
n, m, q = gets.split.map(&:to_i) set = q.times.map {gets.split.map(&:to_i)} maximum = 0 [*1..m].repeated_combination(n) do |seq| score = set.select {|a, b, c, d| seq[b - 1] - seq[a - 1] == c}.sum {_4} maximum = [maximum, score].max end puts maximum