I thought I would write it after fully understanding the D problem, but it will take time, so I will add it as soon as I understand it.
A. Sheep and Wolves Compare the two values.
ABC164a.py
s,w=map(int,input().split())
if w>=s:
print("unsafe")
else:
print("safe")
B. Battle I wondered if I would take a mod, but since it is troublesome to think about the first attack and the second attack, I implement it obediently
ABC164b.py
a,b,c,d=map(int,input().split())
while True:
c-=b
if c<=0:
print("Yes")
exit()
a-=d
if a<=0:
print("No")
exit()
C. Gacha Just count the unique number in the array.
ABC164c.py
n=int(input())
s=[input() for _ in range(n)]
print(len(set(s)))
I wondered if I could finish this time in 10 minutes so far, but I was worried about the D problem and it was 3 complete.
D. Multiple of 2019 If you implement it honestly, it is $ O (N ^ 2) $, so it is definitely TLE. Gununu
ABC164d_TLE.py
s=input()
ans=0
for l in range(len(s)-3):
for r in range(l+4,len(s)+1):
a=s[l:r]
if int(a)%2019==0:
ans+=1
print(ans)
Recommended Posts