Solve AtCoder ABC166 with python

As the title says. I couldn't answer in time, but I'll post it because I filled it all up after the time. We referred to the submission results of many people.

I got some comments, so I did some refactoring.

A It ends with case classification.

# A

S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')

B Create an array of 1 for all elements and rewrite the element corresponding to the person who has the candy to 0. Finally, take the sum of that array.

# B

N, K = map(int, input().split())

sunuke = [1] * N

for i in range(K):
    di = int(input())
    tmp = map(int, input().split())
    for t in tmp:
        sunuke[t-1] = 0
print(sum(sunuke))

C Create an array $ A $ with all zeros and a length of $ N $. The $ A $ element is programmed to contain the maximum elevation of another observatory connected to each observatory. Each time we receive the way $ [a, b] $, we take the element of $ A $ as max of the height of ourselves and the observatory. In the code below, the updated part of $ A [a-1] $ is compared with other observatory $ b $ connected to observatory $ a $, and the larger one is the observatory connected to observatory $ a $ by a road Update as the maximum altitude of the observatory. The same is true for $ A [b-1] $.

# C
N, M = map(int, input().split())
H = list(map(int, input().split()))

A = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    A[a-1] = max(A[a-1], H[b-1])
    A[b-1] = max(A[b-1], H[a-1])
    
res = sum([H[i] > A[i] for i in range(N)])
print(res)

D Since it is guaranteed that there is a solution, you can try it by pushing it from the bottom. The upper limit to see can be estimated to some extent, but since it is guaranteed that there is a solution, I put it in 100000, which is big enough. If $ (A, B) $ is the solution, then $ (A', B') = (-B, -A) $, so if both $ A and B $ are negative, you don't need to check both if they are positive. .. So here we assume $ A> 0 $ and solve by incrementing $ B $ from the lower bound negative region.

# D
import math
X = int(input())

B = -math.floor(math.pow(X, 0.2))
for b in range(B, 1000):
    a = int(math.pow(X + b ** 5, 0.2))
    if a ** 5 - b ** 5 == X:
        break
        
print(a, b)

E You can assemble according to the official explanation.

# E

import collections

N = int(input())
A = list(map(int, input().split()))

d = dict(collections.Counter([i + A[i] for i in range(N)]))
ans = sum([d.get(i - A[i], 0) for i in range(N)])
    
print(ans)

F You can assemble according to the official explanation.

# F

N, A, B, C = list(map(int, input().split()))
d = {'A': A, 'B': B, 'C': C}
res = []
SN = [input() for i in range(N)]
for i in range(N):
    s = SN[i]
    s0 = s[0]
    s1 = s[1]
    
    if d[s0] == d[s1] == 0:
        print('No')
        exit()
    elif d[s0] == 0:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    elif d[s1] == 0:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
    elif i == N-1:
        res.append(s0)
    elif s0 in SN[i+1]:
        d[s0] += 1
        d[s1] -= 1
        res.append(s0)
    else:
        d[s0] -= 1
        d[s1] += 1
        res.append(s1)
        
print('Yes')
for r in res:
    print(r)

Recommended Posts

Solve AtCoder ABC166 with python
Solve AtCoder ABC 186 with Python
Solve AtCoder 167 with 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
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Solve ABC166 A ~ D with Python
Solve Atcoder ABC169 A-D in Python
Solve AtCoder Problems Recommendation with python (20200517-0523)
Solve ABC168 A ~ C with Python
Solved AtCoder ABC 114 C-755 with Python3
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve with Ruby and Python AtCoder ABC133 D Cumulative sum
I wanted to solve ABC160 with Python
Solve Sudoku with Python
Solve ABC169 in Python
Solve POJ 2386 with python
I wanted to solve ABC172 with Python
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Solve "AtCoder version! Ant book (beginner)" with Python!
[Python] Solve equations with sympy
AtCoder ABC 177 Python (A ~ E)
Light blue with AtCoder @Python
ABC163 C problem with python3
AtCoder ABC 178 Python (A ~ E)
Atcoder ABC164 A-C in Python
Solve ABC176 E in Python
AtCoder ABC 176 Python (A ~ E)
Atcoder ABC167 A-D in Python
Solve ABC175 D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
AtCoder ABC 182 Python (A ~ D)
ABC188 C problem with python3
ABC187 C problem with python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
atCoder 173 Python
AtCoder ABC176
Solve Atcoder ABC176 (A, B, C, E) in Python
AtCoder ABC177
Solve with Ruby and Python AtCoder ABC084 D Cumulative sum of prime numbers
solver> Link> Solve Excel Solver with python
Solve ABC036 A ~ C in Python
Template AtCoder ABC 179 Python (A ~ E)
Solve ABC037 A ~ C in Python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC178 D Dynamic programming
Solving with Ruby and Python AtCoder ABC151 D Breadth-first search
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
Solving with Ruby and Python AtCoder ABC011 C Dynamic programming
Solving with Ruby and Python AtCoder ABC153 E Dynamic programming
Solving with Ruby and Python AtCoder ABC138 D Adjacency list