Python beginner Atcoder memo @ KEYENCE 2020, ABC problem

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?

Acknowledgments

Thank you to everyone who referred to the code.

Recommended Posts

Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
AtCoder Beginner Contest 174 C Problem (Python)
Beginner ABC154 (Python)
Beginner ABC156 (Python)
AtCoder ABC 174 Python
python beginner memo (9.1)
AtCoder ABC187 Python
AtCoder ABC188 Python
Beginner ABC155 (Python)
Beginner ABC157 (Python)
Python beginner memo (2)
AtCoder ABC 175 Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
AtCoder ABC 177 Python (A ~ E)
Solve AtCoder ABC166 with python
ABC163 C problem with python3
AtCoder ABC 178 Python (A ~ E)
Atcoder ABC164 A-C in Python
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest # 002 C Problem
AtCoder ABC 176 Python (A ~ E)
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
AtCoder ABC 182 Python (A ~ D)
ABC188 C problem with python3
Solve AtCoder ABC 186 with Python
Atcoder Beginner Contest 152 Kiroku (python)
ABC187 C problem with python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
AtCoder Beginner Contest 166 A Explanation of Problem "A? C" (Python3, C ++, Java)
AtCoder Beginner Contest 174 B Problem "Distance" Explanation (C ++, Python, Java)
AtCoder ABC155 Problem D Pairs Review Note 2 NumPy and Python
AtCoder Beginner Contest 177 B Problem "Substring" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 167 A Problem "Registration" Explanation (Python3, C ++, Java)
AtCoder ABC151 Problem D Speed comparison in C ++ / Python / PyPy
AtCoder Beginner Contest 169 B Problem "Multiplication 2" Explanation (Python3, C ++, Java)
Solve Atcoder ABC169 A-D in Python
Solved AtCoder ABC 114 C-755 with Python3
Template AtCoder ABC 179 Python (A ~ E)
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
Python memo
[AtCoder commentary] Win the ABC165 C problem "Many Requirements" with Python!
python memo
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
atCoder 173 Python
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
Python memo
AtCoder Beginner Contest 175 B Problem "Making Triangle" Explanation (C ++, Python3, Java)
python memo
AtCoder ABC176
Python memo
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 176 B Problem "Multiple of 9" Explanation (Python3, C ++, Java)
AtCoder ABC177
Python memo
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
Python memo
[Python beginner memo] Python character string, path operation