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