結果

問題 No.1330 Multiply or Divide
ユーザー 👑 KazunKazun
提出日時 2021-01-08 23:58:46
言語 PyPy3
(7.3.13)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 701 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 152,708 KB
最終ジャッジ日時 2023-08-10 13:13:17
合計ジャッジ時間 8,659 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,260 KB
testcase_01 AC 184 ms
127,476 KB
testcase_02 RE -
testcase_03 AC 69 ms
71,472 KB
testcase_04 AC 67 ms
71,204 KB
testcase_05 AC 67 ms
71,400 KB
testcase_06 AC 90 ms
89,988 KB
testcase_07 AC 96 ms
91,912 KB
testcase_08 AC 207 ms
152,524 KB
testcase_09 AC 218 ms
152,708 KB
testcase_10 AC 209 ms
152,424 KB
testcase_11 AC 208 ms
152,432 KB
testcase_12 AC 208 ms
152,344 KB
testcase_13 AC 69 ms
71,368 KB
testcase_14 AC 69 ms
71,448 KB
testcase_15 AC 70 ms
71,228 KB
testcase_16 AC 68 ms
71,460 KB
testcase_17 AC 67 ms
71,488 KB
testcase_18 AC 188 ms
152,216 KB
testcase_19 AC 187 ms
152,400 KB
testcase_20 AC 189 ms
152,404 KB
testcase_21 AC 187 ms
152,388 KB
testcase_22 AC 191 ms
152,360 KB
testcase_23 AC 112 ms
96,680 KB
testcase_24 AC 68 ms
71,276 KB
testcase_25 AC 67 ms
71,400 KB
testcase_26 AC 70 ms
71,488 KB
testcase_27 AC 67 ms
71,076 KB
testcase_28 AC 68 ms
71,364 KB
testcase_29 AC 69 ms
71,224 KB
testcase_30 AC 68 ms
71,460 KB
testcase_31 AC 67 ms
71,480 KB
testcase_32 AC 67 ms
71,080 KB
testcase_33 AC 69 ms
71,260 KB
testcase_34 AC 154 ms
115,096 KB
testcase_35 AC 95 ms
90,260 KB
testcase_36 AC 143 ms
131,204 KB
testcase_37 AC 135 ms
125,132 KB
testcase_38 AC 117 ms
106,324 KB
testcase_39 AC 100 ms
94,860 KB
testcase_40 AC 105 ms
99,944 KB
testcase_41 AC 87 ms
85,496 KB
testcase_42 AC 130 ms
119,508 KB
testcase_43 AC 138 ms
125,676 KB
testcase_44 AC 92 ms
89,948 KB
testcase_45 AC 92 ms
89,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline

N,M,P=map(int,input().split())
A=set(map(int,input().split()))
A=list(A)

Max=max(A)

T={}
for b in A:
    a=b
    m=1
    while b%P==0:
        b//=P
        m+=1

    if b>1 and ((b not in T) or (T[b]>m)):
        T[b]=m

if (not T) and Max<=M:
    print(-1)
    exit(0)


def f(x,k):
    if k+1>=Y:
        return float("inf")

    if x in Memo:
        return Memo[x]
    elif x>M:
        return 0
    elif x*Max>M:
        return 1

    X=float("inf")
    for b in T:
        m=T[b]
        if k+m+1<Y:
            X=min(X,f(x*b,k+m)+m)
    Memo[x]=X
    return X

Y=1
x=1
semi=max(T)
while x*Max<=M:
    x*=semi
    Y+=T[semi]

Memo={}

print(min(Y,f(1,0)))
0