Challenge AtCoder (ABC) 164 with Python! A ~ C problem

Introduction

I challenged AtCoder ABC164 with Python! This is the second challenge for Rated. I solved from A to C. The D problem was TLE.

A problem

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")

B problem

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()

C problem

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)))

D problem

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)

Summary

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

Challenge AtCoder (ABC) 164 with Python! A ~ C problem
[AtCoder] Solve ABC1 ~ 100 A problem with Python
ABC163 C problem with python3
ABC188 C problem with python3
ABC187 C problem with python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
ABC166 in Python A ~ C problem
Solve ABC168 A ~ C with Python
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC158 A ~ C with Python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
Solve AtCoder ABC168 with python (A ~ D)
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
[AtCoder commentary] Win the ABC165 C problem "Many Requirements" with Python!
AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 178 Python (A ~ E)
AtCoder ABC 176 Python (A ~ E)
AtCoder ABC 182 Python (A ~ D)
Solve AtCoder ABC 186 with Python
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
Solve Atcoder ABC176 (A, B, C, E) in Python
ABC127 A, B, C Explanation (python)
[AtCoder explanation] Control the A, B, (C), D problems of ABC165 with Python!
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
Solve ABC166 A ~ D with Python
Solve ABC036 A ~ C in Python
Template AtCoder ABC 179 Python (A ~ E)
ABC128 A, B, C commentary (python)
ABC126 A, B, C Explanation (python)
Solve ABC037 A ~ C in Python
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
AtCoder Beginner Contest 174 C Problem (Python)
Solving with Ruby and Python AtCoder ABC011 C Dynamic programming
AtCoder ABC151 Problem D Speed comparison in C ++ / Python / PyPy
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Solve ABC175 A, B, C in Python
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
I wanted to solve the ABC164 A ~ D problem with Python
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
Solving with Ruby, Perl, Java, and Python AtCoder ABC 065 C factorial
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
Solving with Ruby and Python AtCoder ABC057 C Prime Factorization Bit Search
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
Solving with Ruby AtCoder ABC110 C String Manipulation
ABC147 C --HonestOrUnkind2 [Python]
AtCoder Beginner Contest 165 A Problem "We Love Golf" Explanation (Python3, C ++, Java)
Try embedding Python in a C ++ program with pybind11
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)