Last time Results of yesterday's ABC Today we're solving the Boot camp for Beginners Medium.
** Thoughts ** ** Read the question sentence properly **. The element of $ A_i $ must be less than or equal to $ 10 ^ 9 $. It is troublesome to calculate the sum of multiple elements as in the sample. Therefore, it will be easier if you prepare $ K $ pieces of $ S $. If $ S $ is not $ 10 ^ 9 $, the other element is AC if it is $ S $ or more. If $ S $ is $ 10 ^ 9 $, it must be an integer less than or equal to $ 10 ^ 9 $ from the problem statement. Here, if it is an integer other than 1, the sum can be $ 10 ^ 9 $, so the other elements will be 1.
n, k, s = map(int,input().split())
if s < 10**9:
ans = [s] * k + [10**9] * (n-k)
print(*ans)
else:
ans = [s] * k + [1] * (n-k)
print(*ans)
Is it a specification that the color of the page is different only in the Keyence contest?
** Thoughts ** Even though it's green, it's a tea diff. As long as the number of elements is the same for the character string that is an anagram, sort each character string and put it in Counter. ← I think it's easier to write. After that, the combination is calculated for the element whose Counter Value is 2 or more. If it is math.factorial, it becomes RE, so scipy is used.
from collections import Counter
from scipy import misc #Note the version of scipy
n = int(input())
s = [list(input()) for _ in range(n)]
ss = []
for i in range(n):
a = sorted(s[i])
a = ''.join(a)
ss.append(a)
ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
if ss[i] == 1:
continue
if ss[i] >= 2:
ans += round(float(misc.comb(ss[i],2)))
print(int(ans))
** Thoughts ** Let m be the list of [False] * N. When $ P_i = i $, let $ m [i] $ be True, then write $ m [i] = True $ as T and $ m [i] = False $ as F. If the sequence of elements of m is divided, it becomes (TT, TF). (TFT) can also be decomposed into (TF) and (FT). Both (TT, TF) can be set to (FF) with one swap. Because $ P $ doesn't have the same element, it doesn't swap (TF) to (TT). The same is true for (TF). And swap is not done continuously. From the above, if $ m [i] $ is T, it can always be changed to F with one swap.
n = int(input())
p = list(map(int,input().split()))
m = [False] * n
for i in range(n):
if p[i] == i+1:
m[i] = True
ans = 0
flag = False #Check for the presence of the previous swap
for i in range(n):
if flag:
flag = False
continue
if m[i]:
flag = True
ans += 1
print(ans)
Japanese is difficult. I also want to clean the implementation. see you.
Recommended Posts