AtCoder

ABC184

https://atcoder.jp/contests/abc184 A: Determinant a, b, c, d = readlines.join.split.map(&:to_i) puts a * d - b * c B: Quizzes n, x = gets.split.map(&:to_i) str = gets.chomp str.each_char do |s| case s when "o" x += 1 else x -= 1 if x.nonze…

ABC179

https://atcoder.jp/contests/abc179 A: Plural Form str = gets.chomp puts str + (str[-1] == "s" ? "es" : "s") B: Go to Jail n = gets.to_i dice = n.times.map {gets.split.map(&:to_i)} f = dice.each_cons(3).any? {|d1, d2, d3| d1[0] == d1[1] && …

ABC181

https://atcoder.jp/contests/abc181 A: Heavy Rotation n = gets.to_i puts n.even? ? "White" : "Black" B: Trapezoid Sum n = gets.to_i abs = n.times.map {gets.split.map(&:to_i)} puts abs.map {|a, b| (b - a + 1) * (a + b) / 2}.sum C: Collineari…

ABC180

https://atcoder.jp/contests/abc180 A: box n, a, b = gets.split.map(&:to_i) puts n - a + b B: Various distances gets xs = gets.split.map(&:to_i) puts xs.map {_1.abs}.sum puts Math.sqrt(xs.map {_1 * _1}.sum) puts xs.map {_1.abs}.max C: Cream…

ABC175

https://atcoder.jp/contests/abc175 過去問。 A: Rainy Season puts gets.chomp.each_char.chunk {|e| e == "R"} .map {|b, ary| b ? ary.size : 0}.max B: Making Triangle n = gets.to_i ls = gets.split.map(&:to_i) puts ls.combination(3).count {|li,…

ABC174

https://atcoder.jp/contests/abc174 過去問。 A: Air Conditioner x = gets.to_i puts (x >= 30) ? "Yes" : "No" B: Distance n, d = gets.split.map(&:to_i) coordinates = n.times.map {gets.split.map(&:to_i)} puts coordinates.count {|x, y| x * x + …

ABC167

https://atcoder.jp/contests/abc167 過去問。 A: Registration s = gets.chomp t = gets.chomp puts (t[0..-2] == s) ? "Yes" : "No" B: Easy Linear Programming a, b, c, k = gets.split.map(&:to_i) score = 0 if a <= k score += a k -= a if b <= k k …

ABC166

https://atcoder.jp/contests/abc166 A: A?C puts (gets.chomp == "ABC") ? "ARC" : "ABC" B: Trick or Treat n, k = gets.split.map(&:to_i) sunuke = Array.new(n, 0) k.times do gets gets.split.each {|a| sunuke[a.to_i - 1] += 1} end puts sunuke.cou…

AGC033A

A - Darker and Darker TLE のコード H, W = gets.split.map(&:to_i) $field = H.times.map {gets.chomp} Area = W * H class Step @@count = 0 @@max_step = 0 def initialize(x, y, step = 0) @x = x @y = y @step = step @@count += 1 @@max_step = step …

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_…

ABC162

https://atcoder.jp/contests/abc162 過去問。 A: Lucky 7 n = gets.chomp puts n.include?("7") ? "Yes" : "No" B: FizzBuzz Sum n = gets.to_i result = 0 (1..n).each do |i| next if i % 3 == 0 || i % 5 == 0 result += i end puts result C: Sum of gc…

ABC161

https://atcoder.jp/contests/abc161 過去問。 A: ABC Swap a, b, c = gets.split.map(&:to_i) a, b = b, a a, c = c, a puts "#{a} #{b} #{c}" B: Popular Vote n, m = gets.split.map(&:to_i) votes = gets.split.map(&:to_i) limit = Rational(votes.inje…

ABC159

https://atcoder.jp/contests/abc159 過去問。 A: The Number of Even Pairs 偶数から2個か奇数から2個取ればよい。 #x個の中から2個取る組み合わせの数 def c(x) return 0 if x == 0 || x == 1 x * (x - 1) / 2 end n, m = gets.split.map(&:to_i) puts c(n…

ABC158

https://atcoder.jp/contests/abc158 過去問。 A:Station and Bus s = gets.chomp puts (s == "AAA" || s == "BBB") ? "No" : "Yes" B:Count Balls n, a, b = gets.split.map(&:to_i) blue_ball = (n / (a + b)) * a remainder = n % (a + b) blue_ball += (…

パナソニックプログラミングコンテスト2020

https://atcoder.jp/contests/panasonic2020 過去問。 A:Kth Term ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] puts ary[gets.to_i - 1] B:Bishop HかWが 1 の場合を忘れていた。 h, w = g…

キーエンス プログラミング コンテスト 2020

https://atcoder.jp/contests/keyence2020 過去問。 A h, w, n = readlines.map(&:to_i) puts (n / [h, w].max.to_f).ceil B imos法かと思ったが、ちがっていた。 n = gets.to_i data = n.times.map {gets.split.map(&:to_i)}.map {|x, l| [x - l, x + l]} r…

ABC151

https://atcoder.jp/contests/abc151 過去問。 A puts gets.chomp.succ B n, k, m = gets.split.map(&:to_i) sum = gets.split.map(&:to_i).inject(&:+) target = m * n - sum result = case when target < 0 then 0 when target > k then -1 else target en…

ABC152

https://atcoder.jp/contests/abc152 過去問。 A n, m = gets.split.map(&:to_i) puts (n == m) ? "Yes" : "No" B a, b = gets.split.map(&:to_i) result = a.to_s * b tmp = b.to_s * a result = tmp if result > tmp puts result C これはすぐに思いついた…

AtCoder/ABC138

https://atcoder.jp/contests/abc138 A - Red or Not puts (gets.to_i >= 3200) ? gets.chomp : "red" B - Resistors in Parallel gets as = gets.split.map(&:to_i) puts Rational(1, as.map {|i| Rational(1, i)}.inject(:+)).to_f C - Alchemist gets as …

AtCoder/ABC137

A - +-x a, b = gets.split.map(&:to_i) puts [a + b, a - b, a * b].max B - One Clue k, x = gets.split.map(&:to_i) puts [*x - k + 1..x + k - 1].join(" ") C - Green Bin words = gets.to_i.times.map {gets.chomp.chars.sort.join}.group_by(&:itself…

AtCorder/ABC(その1)

ABC001 A - 積雪深差 puts gets.to_i - gets.to_i B - 視程の通報 ans = case (m = gets.to_i) when 0...100 then 0 when 100..5000 then m / 100 when 6000..30000 then m / 1000 + 50 when 35000..70000 then (m / 1000 - 30) / 5 + 80 else 89 end puts s…

CPSCO2019 Session4

CPSCO2019 Session4 - AtCoder A - Swimming l, x = gets.split.map(&:to_i) n = x / l puts n.even? ? x % l : (n + 1) * l - x B - Meeting n, d = gets.split.map(&:to_i) table = d.times.map do gets.chomp.chars.map.with_index {|st, i| i if st == "…

AtCoder(AtCoder Beginners Selection)

AtCoder Beginners Selection - AtCoder PracticeA - はじめてのあっとこーだー(Welcome to AtCoder) a = gets.to_i b, c = gets.split.map(&:to_i) s = gets print "#{a + b + c} #{s}" ABC086A - Product a, b = gets.split.map(&:to_i) puts (a * b).od…