I challenged AtCoder ABC164 with Python! This is the second challenge for Rated. I solved from A to C. The D problem was TLE.
If s is greater than w, it is safe, otherwise it is unsafe.
A.py
s, w = map(int, input().split())
if s > w:
print("safe")
else:
print("unsafe")
In an infinite loop, turn until a or c is less than or equal to 0 Since Takahashi is the first player, if both are negative, Takahashi wins, so let's write the code to process flg1 first.
B.py
a, b, c, d = map(int, input().split())
flg1 = False
flg2 = False
while True:
c -= b
a -= d
if c <= 0:
flg1 = True
if a <= 0:
flg2 = True
if flg1:
print("Yes")
exit()
if flg2:
print("No")
exit()
You can eliminate duplication by changing to set (). The answer is the number without duplication.
C.py
n = int(input())
s = [str(input()) for _ in range(n)]
print(len(set(s)))
Since it is a double loop, the amount of calculation has become too large. This code is TLE.
D.py
s = input()
keta = len(s)
ans = 0
mul = []
for i in range(100):
if "0" in str(2019 * i):
pass
else:
mul.append(str(2019 * i))
for i in range(len(mul)):
for j in range(0, keta + 1 - len(str(mul[i]))):
if s[j : j + len(mul[i])] == mul[i]:
ans += 1
print(ans)
This was my second challenge I thought that problem A could have been solved anyway, but I solved it as B and C without noticing that I had reversed unsafe and safe, so the performance dropped considerably. I want to be careful from the next time
Recommended Posts