結果

問題 No.1330 Multiply or Divide
ユーザー chineristAC
提出日時 2021-01-08 22:56:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 528 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 120,064 KB
最終ジャッジ日時 2024-11-16 14:49:47
合計ジャッジ時間 25,320 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

B = []
for a in A:
    cost = 1
    while a%P==0:
        a //= P
        cost += 1
    if a!=1:
        B.append((cost,a))

if not B:
    exit(print(-1))

n = len(B)
dp = [1 for i in range(601)]
for i in range(n):
    cost,a = B[i]
    next = [dp[j] for j in range(601)]
    for j in range(601-cost):
        next[j+cost] = max(next[j+cost],min(M,dp[j]*a),min(M,next[j]*a))
    dp = next

for i in range(601):
    if dp[i]==M:
        print(i)
        break
0