Atcoder ABC164 A-C in Python

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

Atcoder ABC164 A-C in Python
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Solve Atcoder ABC169 A-D in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Solve ABC169 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python