A Painting Reference: https://atcoder.jp/contests/keyence2020/submissions/9588167
h = int(input()) #h = input()Written as str type
w = int(input())
n = int(input())
ans = min((n+h-1)//h,(n+w-1)//w) #Calculate each and the smaller one is the answer
print(ans)
First, stumble by writing h = input (). In python3, even if I put a numerical value in h, it fits in str type? It is unavoidable to rewrite it as int (input ()). (N + ○ -1) // ○ seems to be frequent, but I wrote redundant code in production.
B Robot Arms Reference: https://atcoder.jp/contests/keyence2020/submissions/9588111
n = int(input())
a = []
for i in range(n):
x,l = map(int,input().split())
a.append([x+l,x-l]) #Store in order of end and tip for easy sorting
a.sort()
ans = 1
bef = a[0]
for i in range(1,n):
aft = a[i]
if (bef[0] <= aft[1]): #The end of the a body robot and a+Compare the tips of the first robot
bef = aft
ans += 1
print(ans)
It seems that it is an interval scheduling problem with almost the reference code. Sort in ascending order of the end (maximum value), and add if it does not cover the robot placed in front. Isn't it too difficult for 200 points?
C Subarray Sum Reference: https://atcoder.jp/contests/keyence2020/submissions/9590293
n,k,s = map(int,input().split())
ans = []
if (s < 1000000000):
for i in range(n):
if (i < k):
ans.append(s)
else:
ans.append(s + 1)
elif (s == 1000000000):
for j in range(n):
if (j < k):
ans.append(s)
else:
ans.append(1)
ans = map(str,ans) #By adding this two-line processing Example:[80,80,81,81,81]→
print(' '.join(ans)) #Can output 80 80 81 81 81
This is also almost the same as the reference code. Of the n elements in the sequence, k should be s and the rest should be other than s. It is set as s + 1 to make a number other than s, and it is divided into cases so that 1000000001 that exceeds the range of the condition does not occur. Honestly, maybe this one was better than B?
Thank you to everyone who referred to the code.
Recommended Posts