Daily AtCoder # 37 in Python

Introduction

Last time We will do Boot camp for Beginners.

#37 ARC091-C

** Thoughts ** Since the number of operations is an even number, the edge will always be a table at the end. Similarly, elements other than edges are manipulated an odd number of times, so they are flipped at the end. Based on the above idea, the number of sheets on the back at the end is $ (n-2) * (m-2) $. However, this does not hold for $ n \ leq2, m \ leq2 . Therefore, the processing for exceptions ( n \ leq2, m \ leq2 $) will be written separately.

n, m = map(int,input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(max(n,m)-2,0))
else:
    print((n-2)*(m-2))

ARC080-C

** Thoughts ** If the multiple of 4 is more than half of all the elements, you can create a sequence that satisfies the condition. What we have to think about here is the process of 2. Unlike other non-multiples of 4, 2 satisfies the condition if it is continuous. Therefore, by subtracting the number of c2 from n and adding 1 to it, the number of 2 can be ignored in the calculation.

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

c1 = 0
c2 = 0
c4 = 0
for i in range(n):
    if a[i] % 4 == 0:
        c4 += 1
    elif a[i] % 2 == 0:
        c2 += 1
    elif a[i] == 1:
        c1 += 1

n -= c2
c2 %= 2
n += c2
f = n // 2

if c4 >= f:
    print('Yes')
    quit()
else:
    print('No')

ABC043-B

** Thoughts ** Just pick up s one by one with for and add it to the string. 'B' was implemented as a slice.

s = input()
ans = ''
for i in range(len(s)):
    if s[i] == 'B':
        ans = ans[:-1]
    elif s[i] == '0':
        ans += '0'
    else:
        ans += '1'
    #print(ans)
print(ans)

ABC131-C

** Thoughts ** I think it's an integer problem. Explanation of formula

import fractions
a, b, c, d = map(int,input().split())

l = int(fractions.gcd(c,d) * c / fractions.gcd(c,d) * d / fractions.gcd(c,d))
#print(l)
x = b // c - a // c
y = b // d - a // d
z = b // l - a // l
if a % c == 0 or a % d == 0:
    print(int(b-a-(x+y-z)))
else:
    print(int(b-a-(x+y-z))+1)
#print(x,y,z)

ABC109-C

** Thoughts ** The answer is the greatest common divisor of the differences between the elements, so just calculate

import fractions
n, y = map(int,input().split())
x = list(map(int,input().split()))

x.append(y)
x.sort()
d = []
for i in range(n):
    d.append(x[i+1]-x[i])
if len(d) !=1:
    ans = fractions.gcd(d[0],d[1])
    for i in range(n-1):
        ans = fractions.gcd(ans,d[i])
    print(ans)
else:
    ans = d[0]
    print(ans)

ABC116-C

** Thoughts ** It is the same to change the height of all flowers from 0 to $ h $ and to change the height of all flowers from $ h $ to 0. Adjacent flowers that have not reached each $ h $ will be watered less often. Also, do not water flowers that have reached $ h $. Therefore, we check whether the number of flowers is 0 and calculate the maximum range that can be watered at one time.

n = int(input())
h = list(map(int,input().split()))

ans = 0
for i in range(max(h)):
    c = 0
    for j in range(n):
        if h[j] != 0:
            h[j] -= 1
            c += 1
        else:
            if c != 0:
                ans += 1
                c = 0
        if j == n-1 and c != 0:
            ans += 1
print(ans)

Summary

I have to finish my school homework ... see you.

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 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 # 13 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
Solve Atcoder ABC169 A-D in Python