I've been programming (main language: Python) for the last two years, and recently started Atcoder and now I'm an ash coder. Since it is a memo writing, the quality is not so high, but I would like to leave a memo mainly on D and E problems for organizing. Please note that the code that appears here is your own code and may not be optimal.
Finished in 2 minutes. My answer
S, T = input().split()
A, B = map(int, input().split())
U = input()
if S == U:
A -= 1
else:
B -=1
print(A, B)
Finished in 1 minute. My answer
S = input()
print('x' * len(S))
Finished in 2 minutes.
Whether or not there is duplication in the element can be determined by comparing len (list)
and len (set)
.
My answer
N = int(input())
A = list(map(int, input().split()))
if len(A) == len(set(A)):
print("YES")
else:
print("NO")
If you want to find the sum of a certain section, you can use the cumulative sum to find it at detonation velocity. Regarding the cumulative sum This article-> Be able to write cumulative sums without thinking! It is explained in detail in.
As a feature of cumulative sum
Take O (N) O (N) time for preprocessing The storage capacity can be O (N) O (N) With pre-processing, you can answer each query with O (1) O (1) at explosive speed.
My answer
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = [0] * 1000000
for i in range(N):
s[i+1] = s[i] + A[i]
max_s = 0
for i in range(N):
if max_s < s[i+K] - s[i]:
max_s = s[i+K] - s[i]
print((max_s+K) / 2)
For such an implementation, use Sliding Window instead of cumulative sum.
N, K = map(int, input().split())
A = list(map(int, input().split()))
expect = [(e + 1) / 2 for e in A]
window = sum(expect[0:K])
max_s = window
for i in range(N - K):
window -= expect[i]
window += expect[i + K]
if window > max_s:
max_s = window
print(max_s)
Note below what I checked because I couldn't solve it.
If you use a technique called digit DP "Find the number of integers between 0 and N that satisfy certain conditions." "Find the maximum value of an integer between 0 and N that meets certain conditions." You can solve such problems. Reference article-> Explanation that can reach the itch of digit DP In the words of this article
If the digit you are looking at is the i-th digit from the top, the flag that determines whether it is less than N is smaller, and there are j non-zero digits, the variable to count is
It should look like dp [i] [smaller] [j]
.
Writing below.
Recommended Posts