結果

問題 No.1330 Multiply or Divide
ユーザー marroncastlemarroncastle
提出日時 2021-01-20 19:58:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 106,752 KB
最終ジャッジ日時 2024-12-23 11:33:18
合計ジャッジ時間 4,807 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, P = map(int, input().split())
A = list(map(int, input().split()))
maxa = max(A)
from collections import defaultdict
dp = defaultdict(lambda: 0)
cnts = [1]*30
for i in range(N):
  cnt = 0
  while A[i]%P==0:
    cnt += 1
    A[i] //= P
  cnts[cnt] = max(cnts[cnt], A[i])
dp[0] = 1
if max(A)==1 and maxa<=M:
  print(-1)
  exit()
ans = 0
p = 1
while p*maxa <= M:
  for i in range(30):
    dp[ans+i+1] = max(dp[ans+i+1], p*cnts[i])
  ans += 1
  p = dp[ans]
if p>M:
  print(ans)
else:
  print(ans+1)
0