Beginner ABC154 (Python)

Click here for the contest page

https://atcoder.jp/contests/abc154 A

s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s: a -= 1
else: b -= 1
print(a, b)

Branch by comparing only s with if statement.
Submission https://atcoder.jp/contests/abc154/submissions/9973325 B

s = input()
ans = 'x' * len(s)
print(ans)

(Length of input string) *'x' is output. I could write it in one line. print (len (input ()) *'x')
Submission https://atcoder.jp/contests/abc154/submissions/9975951 C

def main():
    n = int(input())
    a = list(map(int, input().split()))
    seta = set(a)
    ans = 'YES' if len(a) == len(seta) else 'NO'
    print(ans)    
main()

Since you only have to check if there are duplicate elements, you can combine the list with set () to make one duplicate element. It's OK if you compare the number of these elements and check if they are equal.
Submission https://atcoder.jp/contests/abc154/submissions/9980825 D

def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ex = [0 for _ in range(n)]
    for i in range(n):
        ex[i] = (p[i]+1)/2
    
    sumex = sum(ex[:k])
    tmp = sum(ex[:k])
    for i in range(n-k):
        tmp = tmp + (ex[i+k] - ex[i])
        sumex = max(sumex, tmp)
    print(sumex)
    
main()

If you calculate the sum of the expected values from j = i to i + k-1 in the range of i = 1 ~ n-1, in the worst case it will take N × K = 10 to the 10th power Submission)](https://atcoder.jp/contests/abc154/submissions/9998117). Therefore, prepare the sum of the first to k expected values in tmp as the initial value, and the i + 1th expected value is(ith expected value)-(ith expected value) + (i By setting + k + 1st expected value), you can avoid the trouble of calculating (an image to make a note of?). And updated by comparing with the maximum value sumex at that time.
(Expected value of sum of p_i) = (sum of expected value of p_i), so the calculation of expected value may be summarized at the end.
Submission (after the contest is over) https://atcoder.jp/contests/abc154/submissions/10020043

E and F

I would like to add it if I can AC.

2020/2/10 postscript

Added comments from @ c-yan. Regarding the description of the D problem, the following part seems to work faster after correction. Before correction

ex = [0 for _ in range(n)]

Revised

ex = [0] * n

Furthermore, in this case, you can write in one line including the part below this.


ex = [(p[i]+1)/2 for i in range(n)]

There was a helpful article here as a related article. 8 small differences in processing speed that Python should know

Recommended Posts

Beginner ABC154 (Python)
Beginner ABC156 (Python)
Beginner ABC155 (Python)
Beginner ABC157 (Python)
python beginner memo (9.2-10)
AtCoder ABC 174 Python
python beginner memo (9.1)
Python beginner notes
[Beginner] Python array
AtCoder ABC187 Python
AtCoder ABC188 Python
[Beginner] Python functions
PyQ ~ Python Beginner ~
Python beginner memo (2)
AtCoder ABC 175 Python
Python beginner Zundokokiyoshi
Python beginner Atcoder memo @ KEYENCE 2020, ABC problem
Solve ABC169 in Python
ABC147 C --HonestOrUnkind2 [Python]
AtCoder ABC 177 Python (A ~ E)
ABC168
Solve AtCoder ABC166 with python
ABC164
ABC163 C problem with python3
python super beginner tries scraping
AtCoder ABC 178 Python (A ~ E)
Python
Atcoder ABC164 A-C in Python
Solve ABC176 E in Python
ABC memorandum [ABC163 C --managementr] (Python)
Python beginner launches Discord Bot
ABC174
AtCoder ABC 176 Python (A ~ E)
Atcoder ABC167 A-D in Python
Solve ABC175 D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
ABC175
ABC170
AtCoder ABC 182 Python (A ~ D)
Web scraping beginner with python
ABC188 C problem with python3
[Python beginner] Update pip itself
Solve AtCoder ABC 186 with Python
Atcoder Beginner Contest 152 Kiroku (python)
ABC182
ABC153
ABC187 C problem with python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
ABC memorandum [ABC159 C --Maximum Volume] (Python)
Solve ABC163 A ~ C with Python
ABC127 A, B, C Explanation (python)
Solve ABC166 A ~ D with Python
ABC166 in Python A ~ C problem
Solve Atcoder ABC169 A-D in Python
Let's play with Excel with Python [Beginner]
[Python beginner] Divide one list (5 lines).
Solve ABC168 A ~ C with Python
ABC memorandum [ABC161 C --Replacing Integer] (Python)
Solve ABC036 A ~ C in Python