結果

問題 No.1330 Multiply or Divide
ユーザー 👑 KazunKazun
提出日時 2021-01-08 23:57:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 695 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 157,568 KB
最終ジャッジ日時 2024-04-28 06:08:51
合計ジャッジ時間 6,590 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 188 ms
157,568 KB
testcase_02 RE -
testcase_03 AC 38 ms
51,840 KB
testcase_04 AC 38 ms
51,840 KB
testcase_05 AC 39 ms
52,224 KB
testcase_06 AC 64 ms
80,768 KB
testcase_07 WA -
testcase_08 AC 186 ms
151,232 KB
testcase_09 AC 192 ms
151,076 KB
testcase_10 AC 180 ms
151,108 KB
testcase_11 AC 183 ms
151,232 KB
testcase_12 AC 190 ms
151,452 KB
testcase_13 AC 40 ms
51,840 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 38 ms
52,352 KB
testcase_17 WA -
testcase_18 AC 162 ms
151,044 KB
testcase_19 AC 161 ms
151,356 KB
testcase_20 AC 160 ms
151,308 KB
testcase_21 AC 166 ms
150,952 KB
testcase_22 AC 176 ms
151,020 KB
testcase_23 AC 98 ms
99,952 KB
testcase_24 AC 41 ms
52,224 KB
testcase_25 AC 41 ms
51,712 KB
testcase_26 AC 41 ms
51,840 KB
testcase_27 AC 43 ms
52,224 KB
testcase_28 AC 41 ms
51,712 KB
testcase_29 AC 41 ms
52,352 KB
testcase_30 AC 41 ms
51,840 KB
testcase_31 AC 41 ms
51,712 KB
testcase_32 AC 41 ms
52,224 KB
testcase_33 AC 41 ms
52,224 KB
testcase_34 AC 134 ms
135,424 KB
testcase_35 AC 70 ms
79,616 KB
testcase_36 AC 126 ms
126,848 KB
testcase_37 AC 119 ms
120,128 KB
testcase_38 AC 92 ms
98,176 KB
testcase_39 AC 71 ms
84,864 KB
testcase_40 AC 75 ms
90,752 KB
testcase_41 AC 56 ms
74,496 KB
testcase_42 AC 102 ms
114,176 KB
testcase_43 AC 109 ms
120,832 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

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+=1

Memo={}

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