結果

問題 No.1330 Multiply or Divide
ユーザー 👑 KazunKazun
提出日時 2021-01-09 00:16:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 157,312 KB
最終ジャッジ日時 2024-04-28 06:32:38
合計ジャッジ時間 5,585 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,080 KB
testcase_01 AC 169 ms
157,312 KB
testcase_02 AC 38 ms
51,968 KB
testcase_03 AC 37 ms
51,712 KB
testcase_04 AC 35 ms
52,096 KB
testcase_05 AC 35 ms
52,352 KB
testcase_06 AC 61 ms
80,256 KB
testcase_07 AC 71 ms
86,272 KB
testcase_08 AC 181 ms
151,164 KB
testcase_09 AC 183 ms
151,488 KB
testcase_10 AC 180 ms
151,168 KB
testcase_11 AC 176 ms
151,056 KB
testcase_12 AC 175 ms
151,316 KB
testcase_13 AC 37 ms
52,480 KB
testcase_14 AC 35 ms
51,968 KB
testcase_15 AC 34 ms
52,608 KB
testcase_16 AC 35 ms
52,608 KB
testcase_17 AC 35 ms
51,840 KB
testcase_18 AC 157 ms
151,160 KB
testcase_19 AC 155 ms
151,144 KB
testcase_20 AC 154 ms
150,928 KB
testcase_21 AC 158 ms
150,976 KB
testcase_22 AC 161 ms
151,176 KB
testcase_23 AC 89 ms
99,748 KB
testcase_24 AC 38 ms
52,480 KB
testcase_25 AC 37 ms
51,968 KB
testcase_26 AC 36 ms
52,352 KB
testcase_27 AC 36 ms
52,352 KB
testcase_28 AC 35 ms
51,840 KB
testcase_29 AC 38 ms
51,968 KB
testcase_30 AC 37 ms
51,968 KB
testcase_31 AC 35 ms
52,480 KB
testcase_32 AC 36 ms
51,968 KB
testcase_33 AC 36 ms
52,352 KB
testcase_34 AC 121 ms
135,040 KB
testcase_35 AC 64 ms
80,000 KB
testcase_36 AC 115 ms
126,976 KB
testcase_37 AC 107 ms
120,064 KB
testcase_38 AC 83 ms
98,048 KB
testcase_39 AC 70 ms
84,736 KB
testcase_40 AC 74 ms
91,008 KB
testcase_41 AC 57 ms
74,112 KB
testcase_42 AC 97 ms
113,920 KB
testcase_43 AC 106 ms
120,576 KB
testcase_44 AC 62 ms
80,768 KB
testcase_45 AC 62 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

try:
    Y=1
    x=1
    semi=max(T)
    while x*Max<=M:
        x*=semi
        Y+=T[semi]
except:
    Y=float("inf")

Memo={}

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