This is a review article for beginners of competition professionals.
The solution I write here is written while looking at the commentary and other people's submissions. It may not be what you actually submitted.
Oh, ** Did you do it on Sunday too? ** **
I didn't know the existence of the contest. I didn't see the schedule. That's why I'm solving the problem after the contest is over.
Atcoder seems to hold a contest every Saturday. Next time, I will ask whether ABC or ARC will be held.
If the input is'ABC', output'ARC'. If not, output'ABC'.
S = input()
if S == 'ABC':
print('ARC')
else:
print('ABC')
Each of the K types of sweets will be distributed to children with the number $ \ boldsymbol {A_k} $. The question is how many children have not received the sweets.
I think you should combine the elements of each array, remove the duplication, check the "number of people who were given sweets", and subtract from the total number of people.
N, K = map(int, input().split())
A = []
for _ in range(K):
d = input()
A += list(map(int, input().split()))
print(N - len(set(A)))
↓ is a pattern that I tried to thrust into the set type every time. This one was faster.
N, K = map(int, input().split())
A = set()
for _ in range(K):
d = input()
A = A.union(set(map(int, input().split())))
print(N - len(A))
The question is how many observatories meet the condition "higher than all observatories adjacent to you".
It looks like a graph problem ... but you don't have to think about it that hard. False if the adjacent observatory is taller than you. True if you don't have it. Finally, I checked the number of True and output it.
Note that both observatories with "same height" are False.
N, M = map(int, input().split())
H = list(map(int, input().split()))
good = [True] * N
for _ in range(M):
A, B = map(int, input().split())
A -= 1
B -= 1
if H[A] >= H[B]:
good[B] = False
if H[A] <= H[B]:
good[A] = False
print(sum(good))
It is a problem to output one set of integers (A, B) that satisfies.
How much should the $ A and B $ ranges to meet the $ X \ leq 10 ^ 9 $ limit? What is the number that exceeds $ 10 ^ 9 $ when multiplied by 5?
n = 1
while n**5 < 10**9:
n += 1
print(n)
# 64
I will try to search the whole area by taking about twice this range.
import itertools
X = int(input())
for a, b in itertools.product(range(128), range(-128, 128)):
if(a ** 5 - b ** 5 == X):
print(a, b)
break
I went through.
When I saw the commentary,
It seems correct to think of searching up to $ n $, which satisfies $ n = 120 $. The result is okay, but let's think about it properly. After that, as long as this calculation passes, it is also a good idea to search as wide a range as possible.
E - This Message Will Self-Destruct in 5s
"This message disappears automatically after 5 seconds."
The question is to answer the number that satisfies $ A_i + A_j = j-i $.
ʻItertools.combinations_with_replacement ()` covers everything. It became TLE.
import itertools
N = int(input())
A = list(map(int, input().split()))
count = sum([j-i == A[i-1]+A[j-1] for i, j in itertools.combinations_with_replacement(range(1, N+1), 2)])
print(count)
I don't know and give up. See the commentary. Is it possible to escape from $ O (n ^ 2) $?
It's done. You just have to calculate an independent status for each value.
For the value $ A_i $, calculate the value $ L_i = i + A_i $, $ R_i = i --A_i $. You can calculate the number of combinations where $ L_i = R_j $ by counting how many values are contained in $ R $ and $ L $ respectively.
That's why I implemented it with the following code.
import collections
N = int(input())
A = list(map(int, input().split()))
L = [i + A[i] for i in range(N)]
R = [i - A[i] for i in range(N)]
countL = collections.Counter(L)
countR = collections.Counter(R)
print(sum([countL[n] * countR[n] for n in countL.keys()]))
That's all for this article.
Recommended Posts