A A little confusing for A
S, T = input().split()
A, B = map(int, input().split())
U = input()
if U == S:
print(A - 1, B)
else:
print(A, B - 1)
B There are no particular restrictions. I think it's easier than A
S = list(input())
for _ in range(len(S)):
print("x", end='')
C After all Counter is strong. I wrote YES in lowercase and 1WA. I want to be careful about this kind of mistake in the future (atcoder, if possible, unify either one ...)
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
A = A.values()
for a in A:
if a != 1:
print("NO")
exit()
print("YES")
D Uses the linearity of the expected value. The algorithm requires knowledge of the scale method. I forgot to update tmp_ans and it took a long time to fix the bug.
N, K = map(int, input().split())
p = list(map(int, input().split()))
Expected_val = []
for val in p:
sum_val = (val * (val + 1)) // 2
Expected_val.append(sum_val / val)
# print(Expected_val)
left = 0
right = K
ans = sum(Expected_val[left:right])
tmp_ans = ans
# print(ans)
for i in range(N - K):
tmp_ans = tmp_ans - Expected_val[left + i] + Expected_val[right + i]
if tmp_ans > ans:
ans = tmp_ans
print(ans)
E Digit DP. Since the discrimination method is input, a value that is too large is a signal. I found the code because it was October that I solved it before. I messed with the necessary parts and AC safely. This is nice. I'm glad I was born on earth.
from functools import lru_cache
N = input()
K = int(input())
## lru_Memoize using cache
@lru_cache(maxsize=None)
def rec(k,tight,sum_val):
#When searching to the end, 1 or 0 is returned depending on the problem condition.
if k == len(N):
if sum_val == K and sum_val != 0:
return 1
else:
return 0
#Change the ending condition depending on whether the current digit is tight
x = int(N[k])
if tight:
r = x
else:
r = 9
res = 0
for i in range(r + 1):
if i == 0:
res += rec(k + 1 ,tight and i == r, sum_val)
else:
res += rec(k + 1, tight and i == r, sum_val + 1)
return res
print(rec(0 , True , 0))
F During study. Kencho-san was muttering a mysterious formula, so let's investigate. $ C (r, r) + C (r + 1, r) + ... + C (n, r) = C (n + 1, r + 1) $
Recommended Posts