Löse den Atcoder ABC169 A-D mit Python

4 abgeschlossen. E denkt über 20 Minuten nach und versteht überhaupt nicht. F war TLE.

A Multiplication 1 Kommentar: Nichts besonderes

# ABC169 A Multiplication 1

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

print(a*b)

B Multiplication 2 Kommentar: Zuerst habe ich alles berechnet, aber da es zu "TLE" wurde, habe ich die Methode geändert, es in der Mitte "brechen" zu lassen.

# ABC169 B Multiplication 2

from collections import deque

n = int(input())

a_list = [int(x) for x in input().split()]

if min(a_list) == 0:
    print("0")
else:
    a_dq = deque(a_list)
    ans = 1
    for i in range(n):
        ans *= a_dq.popleft()
        if ans > 10**18:
            break

    if ans > 10**18:
        print("-1")
    else:
        print(ans)

C Multiplication 3 Kommentar: Wie erwartet, als ich es so berechnete, wie es mit "float" ist, wurde es zu "WA", also wechselte ich einmal zur Berechnungsmethode mit einer ganzen Zahl.

# ABC169 C Multiplication 3

a, b = map(lambda x: int(x.replace(".","")), input().split())

print(a*b//100)

D Div Game Kommentar: Nur faktorisieren.

# ABC169 D Div Game

n = int(input())

def factorization(n):
    arr = []
    if n == 1:
        return 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

f_list = factorization(n)
ans = 0

for i in range(len(f_list)):
    _tmp = f_list[i][1]
    j = 1
    while _tmp >= 0:
        _tmp -= j
        j += 1
    ans += j-2

print(ans)

F Knapsack for All Subsets(TLE) Kommentar: Ich habe "dict type" verwendet, weil ich die Anzahl der Elemente und Muster, aus denen $ S $ besteht, beibehalten wollte, aber es wurde "TLE".

# ABC169 F Knapsack for All Subsets

from collections import deque
from collections import Counter

def merge_dict_add_values(d1, d2):
    return dict(Counter(d1) + Counter(d2))

n, s = map(int, input().split())
a_dq = deque([int(x) for x in input().split()])

dp = [[{0:0}] * (s+1) for _ in range(n+1)]
dp[0][0] = {0:1}

for i in range(n):
    _tmp = a_dq.popleft()
    for j in range(s+1):
        if j-_tmp < 0:
            dp[i+1][j] = dp[i][j]
        else:
            _tmp_d = dp[i][j-_tmp]
            _dict = dict()
            for k in _tmp_d.keys():
                _dict[k+1] = _tmp_d[k]
            dp[i+1][j] = merge_dict_add_values(dp[i][j],_dict)

# print(dp[n][s])
ans = 0
for k in dp[n][s].keys():
    v = dp[n][s][k]
    ans += (2**(n-k)) * v
    
print(ans%998244353)

Recommended Posts

Löse den Atcoder ABC169 A-D mit Python
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
AtCoder ABC177 A-D mit Python
Löse ABC169 mit Python
Löse AtCoder ABC166 mit Python
Atcoder ABC164 A-C in Python
Löse ABC176 E in Python
Löse ABC175 D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC 174 Python
Löse ABC036 A ~ C mit Python
Löse den Atcoder ABC176 (A, B, C, E) in Python
Löse ABC037 A ~ C mit Python
AtCoder ABC 175 Python
Löse ABC175 A, B, C mit Python
ABC 157 D - Lösungsvorschläge für Freunde in Python!
[AtCoder] Löse ABC1 ~ 100 Ein Problem mit Python
Ich wollte ABC159 mit Python lösen
Löse AtCoder ABC168 mit Python (A ~ D)
Löse ABC165 A, B, D mit Python
Täglicher AtCoder # 36 mit Python
AtCoder # 2 jeden Tag mit Python
Täglicher AtCoder # 32 in Python
Täglicher AtCoder # 6 in Python
Täglicher AtCoder # 18 in Python
Täglicher AtCoder # 53 in Python
Täglicher AtCoder # 33 in Python
Löse ABC168D in Python
Täglicher AtCoder # 7 in Python
AtCoder # 24 jeden Tag mit Python
Löse ABC167-D mit Python
Täglicher AtCoder # 37 in Python
Löse AtCoder 167 mit Python
AtCoder # 8 jeden Tag mit Python
Täglicher AtCoder # 42 in Python
Löse ABC146-C mit Python
Täglicher AtCoder # 21 mit Python
Täglicher AtCoder # 17 mit Python
Täglicher AtCoder # 38 in Python
Täglicher AtCoder # 54 in Python
Täglicher AtCoder # 15 in Python
Täglicher AtCoder # 47 mit Python
Täglicher AtCoder # 13 in Python
Täglicher AtCoder # 45 mit Python
AtCoder # 30 jeden Tag in Python
Täglicher AtCoder # 40 mit Python
Täglicher AtCoder # 10 mit Python
AtCoder # 5 jeden Tag mit Python
Täglicher AtCoder # 28 in Python
Täglicher AtCoder # 39 in Python
Löse ABC098-C in Python
Täglicher AtCoder # 20 in Python
Täglicher AtCoder # 19 in Python
Täglicher AtCoder # 52 in Python
Täglicher AtCoder # 3 in Python
Täglicher AtCoder # 14 mit Python