結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2021-01-20 19:44:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 553 bytes |
コンパイル時間 | 418 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 689,364 KB |
最終ジャッジ日時 | 2024-12-23 11:15:56 |
合計ジャッジ時間 | 9,630 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 WA * 11 TLE * 1 MLE * 1 |
ソースコード
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)