Daily AtCoder # 33 in Python

Introduction

Last time Today we're filling in the Boot camp for Beginners for At Coder Problems. The difficulty level is Medium.

#33 AGC029-A 1TLE

** Thoughts ** difficult. B and W are switched when the operation is performed. Eventually, W will be on the left and B will be on the right. In order for $ W_i (1 \ leq i \ leq N) $ to go to the left, you must operate on all Bs to the left of that W. So, if you add the number of B to the left of $ W_i (1 \ leq i \ leq N) $, the answer is correct.

s = list(input())

ans = 0
count_b = 0
n = len(s)
for i in range(n):
    if s[i] == 'B':
        count_b += 1
    if s[i] == 'W':
        ans += count_b

print(ans)

ABC139-D 1WA

** Thoughts ** It's a problem with the remainder. Find the maximum sum of the remainders of $ i (1 \ leq i \ leq N $ divided by $ P_i $) for the sequence $ P $, which is a sequence of integers up to $ N $. $ Thinks that integers up to $ N $ are arranged in ascending order. If you continue the operation, the total of the remainder will be 0. If you shift $ P $ by one to the right, it will be $ N-1 $. This is because $ P_i $ is 1 less than $ i $, which means that when you move it to the left, the sum of the remainders is maximized, because when you move it to the left, $ is smaller than $ i $. P_i $ is increased by 1. Then $ i % P_i = i $. Note that the remainder is 0 only at $ P_i = 1 $, the sum of the remainders is $ \ frac {N (N) -1)} {2} $. Detailed proof can be found in the explanation.

n = int(input())

print(n*(n-1)//2)

Summary

I'm worried about ABC tomorrow because I haven't been devoted recently. See you again, good night.

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 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 # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 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