結果

問題 No.1330 Multiply or Divide
ユーザー Navier_Boltzmann
提出日時 2023-09-13 13:05:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 105,220 KB
最終ジャッジ日時 2025-06-20 01:49:43
合計ジャッジ時間 5,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline


N,M,P = map(int,input().split())
A = list(map(int,input().split()))
C = defaultdict(int)
for a in A:
    cnt = 0
    while a%P==0:
        a //= P
        cnt += 1
    C[cnt+1] = max(C[cnt+1],a)

S = max(A)
if S>M:
    print(1)
    exit()

dp = [-1]*(1001)
dp[0] = 1 
f = lambda x:min(x,1000)
for k,v in C.items():
    
    for i in range(1000):
        if dp[i]==-1:
            continue
        dp[f(i+k)] = max(dp[f(i+k)],dp[i]*v)
        
for i in range(1000):
    if dp[i]*S>M:
        print(i+1)
        exit()
print(-1)
0