atcoder.jp
A
Object.alias_method(:■, :method)
def gets(io) = io.gets.chomp
def split(s) = s.split("x").map(&:to_i)
def mul(ary) = ary[0] * ary[1]
def output(e) = STDOUT.puts e
(■(:gets) >> ■(:split) >> ■(:mul) >> ■(:output)).(STDIN)
B
Object.alias_method(:■, :method)
def gets(io) = io.gets.to_i
def output(e) = (STDOUT.puts e; exit)
def main(x)
(2..).each do |n|
if x == n
output(n)
else
x /= n
end
end
end
(■(:gets) >> ■(:main)).(STDIN)
C
Object.alias_method(:■, :method)
def gets(io) = (io.gets; io.readlines(chomp: true))
def output(e) = STDOUT.puts e
def main(query)
sum = [0]
query.each do |q|
tmp = q.split.map(&:to_i)
case tmp[0]
when 1
sum << sum[-1] + tmp[1]
when 2
sum.shift
else
output(sum[tmp[1] - 1] - sum[0])
end
end
end
(■(:gets) >> ■(:main)).(STDIN)
D
Object.alias_method(:■, :method)
def gets(io) = io.gets.to_i
def output(e) = STDOUT.puts e
def amount_of_square(x) = (x - 1/2r) * 2 + 1
def in?(x, y, r) = Math.hypot(x, y) <= r
def x_reduce(x, y, r)
x -= 1 until in?(x, y, r)
x
end
def walk(r)
x, y = r - 1/2r, 1/2r
sum = amount_of_square(x)
loop do
y += 1
if y >= r
return sum.to_i
else
x = x_reduce(x, y, r)
sum += amount_of_square(x) * 2
end
end
end
(■(:gets) >> ■(:walk) >> ■(:output)).(STDIN)