結果

問題 No.1330 Multiply or Divide
ユーザー 👑 KazunKazun
提出日時 2021-01-08 23:58:46
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 701 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 157,312 KB
最終ジャッジ日時 2024-04-28 06:26:22
合計ジャッジ時間 6,122 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,840 KB
testcase_01 AC 188 ms
157,312 KB
testcase_02 RE -
testcase_03 AC 41 ms
51,840 KB
testcase_04 AC 41 ms
51,840 KB
testcase_05 AC 42 ms
51,712 KB
testcase_06 AC 71 ms
80,256 KB
testcase_07 AC 80 ms
85,504 KB
testcase_08 AC 211 ms
151,156 KB
testcase_09 AC 210 ms
151,292 KB
testcase_10 AC 200 ms
151,156 KB
testcase_11 AC 197 ms
150,888 KB
testcase_12 AC 203 ms
151,316 KB
testcase_13 AC 41 ms
51,832 KB
testcase_14 AC 41 ms
51,712 KB
testcase_15 AC 41 ms
51,968 KB
testcase_16 AC 42 ms
51,712 KB
testcase_17 AC 42 ms
51,712 KB
testcase_18 AC 175 ms
151,016 KB
testcase_19 AC 177 ms
150,928 KB
testcase_20 AC 177 ms
151,000 KB
testcase_21 AC 178 ms
150,784 KB
testcase_22 AC 180 ms
151,016 KB
testcase_23 AC 99 ms
99,584 KB
testcase_24 AC 40 ms
51,584 KB
testcase_25 AC 41 ms
51,712 KB
testcase_26 AC 41 ms
51,584 KB
testcase_27 AC 42 ms
51,584 KB
testcase_28 AC 42 ms
52,096 KB
testcase_29 AC 42 ms
51,584 KB
testcase_30 AC 41 ms
51,584 KB
testcase_31 AC 42 ms
51,584 KB
testcase_32 AC 42 ms
51,712 KB
testcase_33 AC 41 ms
51,712 KB
testcase_34 AC 135 ms
135,040 KB
testcase_35 AC 69 ms
79,488 KB
testcase_36 AC 126 ms
126,592 KB
testcase_37 AC 119 ms
119,716 KB
testcase_38 AC 92 ms
97,796 KB
testcase_39 AC 75 ms
84,864 KB
testcase_40 AC 84 ms
90,496 KB
testcase_41 AC 66 ms
73,728 KB
testcase_42 AC 113 ms
113,536 KB
testcase_43 AC 120 ms
120,832 KB
testcase_44 AC 71 ms
81,024 KB
testcase_45 AC 70 ms
80,640 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