Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atcoder beginner selections #1

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions abs/ABC049C.rb
@@ -0,0 +1,24 @@
s = gets.chomp

exit if s.length > 10 ** 5

while s.length > 0
if s.index("eraser") == 0
s.slice!(0, 6)
elsif s.index("erase") == 0
s.slice!(0, 5)
elsif s.index("dreameraser") == 0
s.slice!(0, 11)
elsif s.index("dreamerase") == 0
s.slice!(0, 10)
elsif s.index("dreamer") == 0
s.slice!(0, 7)
elsif s.index("dream") == 0
s.slice!(0, 5)
else
break
end
end

result = s.length == 0 ? "YES" : "NO"
puts result
8 changes: 8 additions & 0 deletions abs/ABC081A.rb
@@ -0,0 +1,8 @@
input = gets.to_i(2)
result = 0

(0..2).each do |num|
result += input[num]
end

print "#{result}\n"
22 changes: 22 additions & 0 deletions abs/ABC081B.rb
@@ -0,0 +1,22 @@
n = gets.to_i
given = gets.chomp.split(' ').map(&:to_i)

counter = 0
condition_violated = false

while true do
n.times do |num|
if given[num] % 2 == 0
given[num] = given[num] / 2
else
condition_violated = true
break
end
end
if condition_violated
break
end
counter += 1
end

puts counter
26 changes: 26 additions & 0 deletions abs/ABC083B.rb
@@ -0,0 +1,26 @@
input = gets.chomp.split(' ').map(&:to_i)

N = input[0]
A = input[1]
B = input[2]

BASE = 10

exit unless A && B && N
exit if BASE ** 4 < N || A < 1|| B < A || 36 < B

applied_sum = 0

(1..N).each do |num|
num_digit = Math.log10(num).to_i
sum = 0
remain = num
num_digit.downto(0) do |digit|
target_digit_num = remain / (BASE ** digit)
remain -= target_digit_num * (BASE ** digit)
sum += target_digit_num
end
applied_sum += num if A <= sum && sum <= B
end

puts applied_sum
14 changes: 14 additions & 0 deletions abs/ABC085B.rb
@@ -0,0 +1,14 @@
N = gets.to_i
input = []

N.times do |num|
input << gets.to_i
end

tower = []

input.each do |num|
tower << num if tower.select { |val| val == num }.count == 0
end

puts tower.length
16 changes: 16 additions & 0 deletions abs/ABC085C.rb
@@ -0,0 +1,16 @@
N, Y = gets.chomp.split(' ').map(&:to_i)

max_10000yen_count = Y / 10000

(0..max_10000yen_count).each do |num_1|
remain = N - num_1
(0..remain).each do |num_2|
num_3 = N - num_1 - num_2
if Y - (num_1 * 10000 + num_2 * 5000 + num_3 * 1000) == 0
puts "#{num_1} #{num_2} #{num_3}"
exit
end
end
end

puts "-1 -1 -1"
50 changes: 50 additions & 0 deletions abs/ABC086C.rb
@@ -0,0 +1,50 @@
class Point
def initialize(x, y)
@x = x
@y = y
end

def length_to(x, y)
(@x - x).abs + (@y - y).abs
end

def update(x, y)
@x = x
@y = y
end
end

N = gets.chomp.to_i
exit if N > 10 ** 5

itinerary = []
N.times do |num|
t, x, y = gets.chomp.split(' ').map(&:to_i)
itinerary << [t, x, y]
end

current_position = Point.new(0, 0)
current_time = 0
goal = true

itinerary.each do |destination|
t, x, y = destination
length = current_position.length_to(x, y)
remain_time = t - current_time

if length > remain_time
goal = false
break
end

if (length.odd? && remain_time.even?) || (length.even? && remain_time.odd?)
goal = false
break
end

current_position.update(x, y)
current_time = t
end

answer = goal ? "Yes" : "No"
puts answer
40 changes: 40 additions & 0 deletions abs/ABC087B.rb
@@ -0,0 +1,40 @@
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

A_PRICE = 500
B_PRICE = 100
C_PRICE = 50

counter = 0

a_arr = []
b_arr = []
c_arr = []

(0..A).each do |num|
a_arr << A_PRICE * num
end

(0..B).each do |num|
b_arr << B_PRICE * num
end

(0..C).each do |num|
c_arr << C_PRICE * num
end

(0..A).each do |num_a|
a_price = A_PRICE * num_a
(0..B).each do |num_b|
b_price = B_PRICE * num_b
(0..C).each do |num_c|
c_price = C_PRICE * num_c
sum = a_price + b_price + c_price
counter += 1 if sum == X
end
end
end

puts counter
22 changes: 22 additions & 0 deletions abs/ABC088B.rb
@@ -0,0 +1,22 @@
N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)

exit unless 1 <= N && N <= 100
arr.each do |num|
exit unless 1 <= num && num <= 100
end

alice_result = 0
bob_result = 0

counter = 0
arr.sort.reverse.each do |num|
if counter.even?
alice_result += num
else
bob_result += num
end
counter += 1
end

puts alice_result - bob_result