結果

問題 No.1330 Multiply or Divide
コンテスト
ユーザー marroncastle
提出日時 2021-01-20 19:44:51
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
MLE  
実行時間 -
コード長 553 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 148 ms
コンパイル使用メモリ 85,760 KB
実行使用メモリ 827,800 KB
最終ジャッジ日時 2026-05-29 11:47:40
合計ジャッジ時間 4,218 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 MLE * 1 -- * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, M, P = map(int, input().split())
A = list(map(int, input().split()))
maxa = max(A)
from collections import defaultdict
dp = defaultdict(lambda: float('inf'))
cnts = [1]*N
for i in range(N):
  while A[i]%P==0:
    cnts[i] += 1
    A[i] //= P
from heapq import *
lis = []
x = 1
dp[1] = 0
if max(A)==1 and maxa<=M:
  print(-1)
  exit() 
while x * maxa <= M:
  for i in range(N):
    if dp[x*A[i]]==float('inf'):
      heappush(lis, x*A[i])
    dp[x*A[i]] = min(dp[x*A[i]], dp[x]+cnts[i])
  x = heappop(lis)
if x>M:
  print(dp[x])
else:
  print(dp[x]+1)
0