結果

問題 No.1330 Multiply or Divide
ユーザー roaris
提出日時 2021-06-04 17:44:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 106,104 KB
最終ジャッジ日時 2025-06-20 01:38:08
合計ジャッジ時間 6,020 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, M, P = map(int, input().split())
A = list(map(int, input().split()))
Ma = max(A)
d = defaultdict(int)

for Ai in A:
    cost = 1
    
    while Ai%P==0:
        cost += 1
        Ai //= P
    
    d[cost] = max(d[cost], Ai)

dp = [0]*1000
dp[0] = 1

for i in range(1000):
    for k, v in d.items():
        if i+k<1000:
            dp[i+k] = max(dp[i+k], dp[i]*v)

for i in range(1000):
    if dp[i]*Ma>M:
        exit(print(i+1))

print(-1)
0