AtCoder ABC 178 Python (A ~ E)

Summary

Only A and B can be solved. I have no choice but to solve the problem in a straightforward manner while being appalled by my unsolvableness. This time it was a math session (?).

problem

https://atcoder.jp/contests/abc178

A. Not image.png

Answer

x = int(input())

if x == 0:
    print(1)
else:
    print(0)

I think there are various ways to write it, but I honestly wrote it in an if statement.

B. Product Max image.png

Answer

a, b, c, d = map(int, input().split())
answer = 0

if a < 0 and 0 <= b:
    if c < 0 and 0 <= d:
        answer = max(a * c, b * d)
    elif 0 <= c and 0 <= d:
        answer = b * d 
    elif c < 0 and d < 0:
        answer = a * c

elif 0 <= a and 0 <= b:
    if c < 0 and 0 <= d:
        answer = b * d
    elif 0 <= c and 0 <= d:
        answer = b * d
    elif c < 0 and d < 0:
        answer = a * d

elif a < 0 and b < 0:
    if c < 0 and 0 <= d:
        answer = a * c
    elif 0 <= c and 0 <= d:
        answer = b * c
    elif c < 0 and d < 0:
        answer = a * c

print(answer)

In the middle of writing the if statement, I thought "I can do it with max ...", but I wrote all the cases without turning back. Even if you don't divide it like this, you can solve it with max as shown below.


a, b, c, d = map(int, input().split())
answer = max(a*c, a*d, b*c, b*d)
print(answer)

C. Ubiquity image.png

Answer (AC at a later date)

MOD = 10**9 + 7
N = int(input())

#At least 0 is included
in0 = 10**N - 9**N
#At least 0 is included
in9 = 10**N - 9**Nu
#There is 0 or 9
0and9 = 10**N - 8**N

answer = in0 + in9 - 0and9

print(answer%MOD)

I had an answer to my throat, but for some reason I couldn't come up with an answer. Since it cannot be counted normally, it is calculated by subtracting from the whole. The image below. image.png

D. Redistribution image.png

Answer (at a later date)


MOD = 10**9 + 7
S = int(input())

dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= MOD

print(dp[S])

Answer by snuke As it is.

dpI only know what I knew. If you look at the explanation, you can see that it is "certainly", but when you are actually told to solve it within the time limit, you cannot solve `` `DP```. Not enough training ...

E. Dist Max image.png

Answer (at a later date)

N = int(input())

a, b = [], []
for i in range(N):
    x, y = map(int, input().split())
    a.append(x+y)
    b.append(x-y)

a.sort()
b.sort()

answer = max(a[-1] - a[0], b[-1] - b[0])
print(answer)

This is also snuke's answer as it is.

I learned how to transform the formula of max.

Recommended Posts

AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 178 Python (A ~ E)
AtCoder ABC 176 Python (A ~ E)
Template AtCoder ABC 179 Python (A ~ E)
AtCoder ABC 182 Python (A ~ D)
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Solve Atcoder ABC176 (A, B, C, E) in Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Solve AtCoder ABC168 with python (A ~ D)
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Solve AtCoder ABC166 with python
Atcoder ABC164 A-C in Python
Solve ABC176 E in Python
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Solve AtCoder ABC 186 with Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
atCoder 173 Python
AtCoder ABC176
Review of atcoder ABC158, up to question E (Python)
AtCoder ABC177
Solve ABC163 A ~ C with Python
ABC127 A, B, C Explanation (python)
Solve ABC166 A ~ D with Python
ABC166 in Python A ~ C problem
Solve Atcoder ABC169 A-D in Python
Solve ABC168 A ~ C with Python
[Python] Now a brown coder ~ [AtCoder]
Solve ABC036 A ~ C in Python
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
ABC128 A, B, C commentary (python)
Solve ABC158 A ~ C with Python
ABC126 A, B, C Explanation (python)
Solve ABC037 A ~ C in Python
[Python] I'm a green coder ~ [AtCoder]
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC153 E Dynamic programming
AtCoder ABC168 A case expression solved in Ruby and Python
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
Beginner ABC154 (Python)
Beginner ABC156 (Python)
Solve ABC175 A, B, C in Python
[Python] [Explanation] AtCoder Typical DP Contest: A Contest
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
Beginner ABC155 (Python)
AtCoderBeginnerContest154 Participation memo (Python, A ~ E problem)
Solve ABC165 A, B, D in Python
Beginner ABC157 (Python)
Learn dynamic programming in Python (A ~ E)
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!