結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2021-01-20 19:40:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 608 bytes |
コンパイル時間 | 454 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 580,356 KB |
最終ジャッジ日時 | 2024-12-23 11:11:01 |
合計ジャッジ時間 | 12,083 ms |
ジャッジサーバーID (参考情報) |
judge5 / 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')) check = defaultdict(lambda: False) 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): dp[x*A[i]] = min(dp[x*A[i]], dp[x]+cnts[i]) if not check[x*A[i]]: heappush(lis, x*A[i]) check[x*A[i]] = True x = heappop(lis) if x>M: print(dp[x]) else: print(dp[x]+1)