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