結果
問題 | No.1330 Multiply or Divide |
ユーザー |
|
提出日時 | 2021-01-20 19:52:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 752 ms / 2,000 ms |
コード長 | 462 bytes |
コンパイル時間 | 412 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 108,672 KB |
最終ジャッジ日時 | 2024-12-23 11:24:39 |
合計ジャッジ時間 | 6,009 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
ソースコード
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]*N for i in range(N): while A[i]%P==0: cnts[i] += 1 A[i] //= P 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(N): dp[ans+cnts[i]] = max(dp[ans+cnts[i]], p*A[i]) ans += 1 p = dp[ans] if p>M: print(ans) else: print(ans+1)