Atcoder ABC169 A-E in Python

It was the worst performance ever: (

A: Multiplication 1 Just do it.

ABC169a.py


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

print(a*b)

B: Multiplication 2 Even though $ N <10 ^ 5 $, if you turn it normally, it becomes TLE. However, I tried to get out of the loop on the way. ~~ It may take some time to calculate when it overflows (although it is WA when it overflows in the first place). ~~

ABC169b.py


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

ans=1

if 0 in a:
    print(0)
    exit()

for i in a:
   ans*=i
   if ans>10**18:
    print(-1)
    exit()


print(ans)

C: Multiplication 3 Commentary AC. If you feel that you need high-precision calculations, just use Decimal instead of Float when dealing with floating-point types. Knowledge problem.

ABC169c.py


from decimal import Decimal
from math import floor

a,b=map(Decimal,input().split())

print(floor(a*b))

D: Div Game How many types of $ z $ can I prepare? In other words. Since $ z $ can be expressed as a power of the prime factors of $ N , the number of the same prime factors is counted for each prime factor, and 2 or less ⇒ 1 and 3 or more and less than 6 ⇒ 2 ( p ^ 1 $, $) p ^ 2 ), 6 or more and less than 10 ⇒ 3 ( p ^ 1 $, $ p ^ 2 $, $ p ^ 3 $), etc., which can be expressed by each prime factor All you have to do is count up the numbers. Since it is $ 2 ^ {43}> 10 ^ {12} $, it is OK if you think about the number of each prime factor up to 42 at most. The exception is 0 if it is 1. For the function part of prime factorization, I referred to here.

ABC169d.py


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
    
a=factorization(int(input()))

b=[1,3,6,10,15,21,28,36,43]

ans=0
if len(a)==1 and a[0][0]==1:
    print(0)
    exit()

for i in a:
    for j in range(len(b)):
        if i[1]<b[j]:
            ans+=j
            break
print(ans)

E: Count Median The value that can be taken as the median of the whole between the median of the set of A and the median of the set of B. If N is an even number, it will be in 0.5 increments, and if it is odd, it will be in 1 increments.

ABC169e.py


def median(q):
    l=len(q)
    q=sorted(q,reverse=True)
    if l%2==0:
        return (q[int(l/2)]+q[int(l/2)-1])/2
    else:
        return q[int((l+1)/2-1)]

n=int(input())

a=[]
b=[]

for i in range(n):
   x,y=map(int,input().split())
   a.append(x)
   b.append(y)
   
med_a=median(a)
med_b=median(b)

if n%2==0:
    print(int(2*(med_b-med_a)+1))
    
else:
    print((med_b-med_a)+1)

By the way, I personally don't like the B-C question format this time, although it's about eight WAs. If you use the same mind, I would like to think about an algorithm that breaks through the constraints, not the implementation constraints themselves ... If these problems continue to be asked, I feel that Atcoder is not recommended to my novice friends. It was.

Recommended Posts

Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
Atcoder ABC164 A-C in Python
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
AtCoder ABC177 A-D in python
AtCoder ABC 174 Python
AtCoder ABC187 Python
AtCoder ABC188 Python
AtCoder ABC 175 Python
Solve Atcoder ABC169 A-D in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 38 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 # 10 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 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 # 27 in Python
Daily AtCoder # 1 in Python
Solve ABC169 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 # 44 in Python
Daily AtCoder # 41 in Python
AtCoder ABC 177 Python (A ~ E)
Solve AtCoder ABC166 with python
AtCoder ABC 178 Python (A ~ E)
Solve ABC176 E in Python
Python Input Note in AtCoder
AtCoder ABC 176 Python (A ~ E)