Daily AtCoder # 49 in Python

Introduction

Last time Results of yesterday's ABC スクリーンショット 2020-04-27 17.43.12.png Today we're solving the Boot camp for Beginners Medium.

#49 Keyence Contest 2020-C

** 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?

ABC137-C

** 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))

ABC072-D

** 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)

Summary

Japanese is difficult. I also want to clean the implementation. see you.

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python