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)
I'm worried about ABC tomorrow because I haven't been devoted recently. See you again, good night.
Recommended Posts