Daily AtCoder # 52 in Python

Introduction

Last time Today, I will solve 3 AGC-A questions.

#52 AGC040-A

** Thoughts ** I understood the idea, but I couldn't implement it. Let $ a $ be a list of $ [0] * (n + 1) $. I wasn't able to implement it because I was trying to handle both'<' and'>' together. N is also about $ 5 * 10 ^ 5 $, so $ O (2N) (complexity ignoring coefficients) $ will pass. First, process from'<'. If $ s [i] =='<' $, then $ a [i + 1] $ becomes $ a [i] + 1 $. Next, we will process'>', but some ingenuity is required. '>' Must be calculated from the back because of the inequality sign. So, multiply range (n) by reversed. If $ s [i] =='>' $, take $ a [i] = max (a [i + 1] + 1, a [i]) $. Finally, take $ sum (a) $.

s = list(input())
n = len(s)

a = [0] * (n+1)
for i in range(n):
    if s[i] == '<':
        a[i+1] = a[i]+1
for i in reversed(range(n)):
    if s[i] == '>':
        a[i] = max(a[i+1]+1,a[i])
print(sum(a))

AGC015-A

** Thoughts ** Since $ N = 10 ^ 9 $, $ O (N) $ will not pass. $ n = 1 $ → 1 if $ a = b $, 0 if $ a \ neq b $. Also, it is 0 when $ a $> $ b $ and 1 when $ a $ = $ b $. Consider the other cases. The minimum sum is not when $ a * n $. This is because the maximum value does not reach $ b $ when all are $ a $. Therefore, it becomes $ a (n-1) + b $. Similarly, the maximum sum is $ b (n-1) + a $. You can make everything from $ a (n-1) + b $ to $ b (n-1) + a $. Therefore, the number of sums is $ b (n-1) + a- {a (n-1) + b} + 1 $. If you calculate this, you can transform it into $ (b-a) (n-2) + 1 $. It can be calculated without transforming the formula, but it was transformed because it should be clean.

n, a, b = map(int,input().split())

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif a >= b:
    if a == b:
        print(1)
    else:
        print(0)
else:
    ans = (b-a)*(n-2)+1
    print(ans)

AGC006-A

** Thoughts ** Since $ N $ is small enough, look for $ N $ in order in either slice of $ s or t $ to find the maximum value it contains in the other.

n = int(input())
s = input()
t = input()

c = 0
for i in range(n):
    d = t[:i]
    if d in s:
        c = i
if s == t: #You can write earlier and skip the for process
    print(n)
else:
    print(2*n-c)

Summary

Why does AGC-A have a difficult impression? It will be brown at this week's ABC. See you again, good night.

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python