AtCoder ABC175 This is a summary of the problems of AtCoder Beginner Contest 175, which was held on Saturday, 2020-08-15, 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 There is a continuous $ 3 $ day weather record for the town of AtCoder. The weather record is represented by the string $ S $ of length $ 3 $, and the weather on the $ i (1 \ leqq i \ leqq 3) $ day is sunny when the $ i $ letter is "S", "R" "It was raining at that time. Find the maximum number of consecutive rainy days.
As it is written in the commentary, there are only 8 ways for 3 days, so you can pass it if you write it separately. If you pay attention to the order of the conditions, you can solve it in the following cases.
abc175a.py
n = input()
if "RRR" in n:
print(3)
elif "RR" in n:
print(2)
elif "R" in n:
print(1)
else:
print(0)
Problem statement There are $ N $ sticks numbered $ 1, ⋯, N $. The length of the bar $ (i (1 \ leqq i \ leqq N) $ is $ L_i $. How many of these are the $ 3 $ sticks of different lengths that can be used to make a triangle? In other words, find the number of $ 3 $ integers $ 1 \ leqq i <j <k \ leqq N $ pairs that satisfy both of the following $ 2 $ conditions. ・ $ L_i, L_j, L_k $ are all different ・ There is a triangle whose side length is $ L_i, L_j, L_k $.
Since the condition that all sides are different is easy, regarding the condition that a triangle holds, if the length of $ 3 $ side is $ L_i <L_j <L_k $, the triangle exists when $ L_i + L_j> L_k $. By first sorting the $ N $ bars, when you select $ 3 $ from $ N $, the rightmost one of the selected $ 3 $ will be the largest value. Since $ N $ is 100 or less, you can check all combinations in time.
abc175b.py
n = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
count = 0
for i in range(0, n - 2):
for j in range(i + 1, n - 1):
for k in range(j + 1, n):
a = l_list[i]
b = l_list[j]
c = l_list[k]
if a == b or b == c or c == a:
continue
if a + b > c:
count += 1
else:
break
print(count)
Problem statement Takahashi, who lives on the number line, is now at coordinates $ X $. From now on, Mr. Takahashi intends to repeat the act of moving $ D $ in the positive or negative direction of the coordinates just $ K $ times. More precisely, a $ 1 $ move can move from the coordinates $ x $ to $ x + D $ or $ x−D $. Takahashi wants to move so that the absolute value of the coordinates after moving just $ K $ times is the minimum. Find the minimum possible value as the absolute value of the coordinates after moving $ K $ times.
Initially, it is in the coordinates $ X $, but since the minimum value to be obtained is the absolute value of the coordinates, the answers of $ X $ and $ -X $ match. Considering the case of $ 0 \ leqq X $, if there is no limit on the number of movements $ K $, the remainder $ T1 $ obtained by dividing $ X $ by $ D $ or $ T2 obtained by subtracting $ D $ from $ T1 $. Either $ is the answer. (I want to reduce the absolute value of the coordinates, so it is best to go back and forth near the origin) First, it is determined whether $ T1 $ can be reached, and if it cannot be reached, the answer is $ X $ minus the number of moves x $ D $. If you can reach $ T1 $, you must move $ K $ times, so calculate the remaining number of moves from the number of moves so far, and whether the remaining number of moves is even or odd, $ T1 $ $ T2 $ is determined. Note the output because $ T2 $ is negative.
abc175c.py
x, k, d = map(int, input().split())
if x < 0:
x *= -1
t1 = x % d
t2 = t1 - d
n = (x - t1) // d
if k < n:
print(x - k * d)
else:
n = k - n
if n % 2 == 0:
print(t1)
else:
print(-t2)
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