AtCoder ABC176 This is a summary of the problems of AtCoder Beginner Contest 176, which was held on Saturday, 2020-08-22, in order from problem A, taking into consideration the consideration. The first half deals with problems up to ABC. The problem is quoted, but please check the contest page for details. Click here for the contest page Official commentary PDF
Problem statement Takahashi likes takoyaki. With the takoyaki machine, you can make up to $ X $ takoyaki for every $ 1 $. The time it takes is $ T $ regardless of the number you make. How many minutes do you need to make $ N $ takoyaki?
As you can see in the explanation, the number of times to bake takoyaki is the number of times $ N / X $ is rounded up, but I was unfamiliar with thinking about it and implementing it, so I wrote it in a for statement to speed up the time to submit. Was submitted.
abc176a.py
n, x, t = map(int, input().split())
for i in range(1, 2 * n):
if n <= i * x:
print(i * t)
break
Actually, I think the following program is ideal because it should not make a useless loop.
abc176a.py
n, x, t = map(int, input().split())
k = (n + x - 1) // x
print(k * t)
Problem statement The integer $ N $ is a multiple of $ 9 $ and the sum of the numbers in each digit when $ N $ is expressed in decimal is equivalent to being a multiple of $ 9 $. Determine if $ N $ is a multiple of $ 9 $.
Every time I add a digit number, I calculate the remainder so that the value does not increase, but in the case of python, it was okay to do it only once at the end.
abc176b.py
n = input()
t = 0
for i in range(len(n)):
t += int(n[i])
t = t % 9
if t == 0:
print("Yes")
else:
print("No")
Problem statement $ N $ people are in the $ 1 $ column, and the $ i $ th person from the front is $ A_i $ tall. I would like to install a stepping stone with a height of $ 0 $ or more at each person's feet so that everyone can meet the following conditions. Condition: When comparing heights with a stepping stone, no one is taller than you Find the minimum total height of the steps when this condition is met.
In order from the second person, if the height is shorter than that of the previous person, install the step so that the height is the same as that of the previous person. The answer is the sum of the steps installed.
abc176c.py
n = int(input())
a_list = list(map(int, input().split()))
total = 0
for i in range(1, n):
if a_list[i - 1] > a_list[i]:
total += a_list[i - 1] - a_list[i]
a_list[i] = a_list[i - 1]
print(total)
This is the end of the first half. I am on summer vacation, but since my dissertation has been conditionally accepted and I am busy writing answers, I would like to write in the second half when I have time. Thank you for reading until the end.
Recommended Posts