AtCoderBeginnerContest154 Participation memo (Python, A ~ E problem)

at first

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.

A problem

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)

B problem

Finished in 1 minute. My answer

S = input()
print('x' * len(S))

C problem

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

D problem

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)

E problem

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

AtCoderBeginnerContest154 Participation memo (Python, A ~ E problem)
AtCoder ABC 177 Python (A ~ E)
AtCoder ABC 178 Python (A ~ E)
ABC166 in Python A ~ C problem
[Python] Creating a scraping tool Memo
Template AtCoder ABC 179 Python (A ~ E)
Python memo
python memo
Python memo
python memo
Python memo
Python memo
Python memo
A memo with Python2.7 and Python3 on CentOS
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Learn dynamic programming in Python (A ~ E)
A memo of a tutorial on running python on heroku
[Python] Memo dictionary
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Try to calculate a statistical problem in Python
python beginner memo (9.2-10)
ARC # 016 Participation memo
python memo: Treat lists as a set type
python beginner memo (9.1)
A memo about writing merge sort in Python
[Memo] I tried a pivot table in Python
★ Memo ★ Python Iroha
A memo when creating a python environment with miniconda
[Python] EDA memo
Python 3 operator memo
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
A memo for creating a python environment by a beginner
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Python beginner memo (2)
[Python] Numpy memo
A memo connected to HiveServer2 of EMR with python
[Python] A memo to write CSV vertically with Pandas
A memo that I touched the Datastore with python
A memo about building a Django (Python) application with Docker
Solve Atcoder ABC176 (A, B, C, E) in Python
A python regular expression, or a memo of a match object
Memo for building a machine learning environment using Python
Python class (Python learning memo ⑦)
A * algorithm (Python edition)
My python environment memo
python openCV installation (memo)
[Python] Take a screenshot
Visualization memo by Python
A python lambda expression ...
[Python] Memo about functions
Daemonize a Python process
python regular expression memo
Binary search (python2.7) memo
[My memo] python -v / python -V
Python3 List / dictionary memo
[Memo] Python3 list sort
Python Tips (my memo)
[Python] Memo about errors