結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-15 09:43:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 726 bytes |
| コンパイル時間 | 662 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 111,764 KB |
| 最終ジャッジ日時 | 2024-11-21 07:15:47 |
| 合計ジャッジ時間 | 5,030 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 43 WA * 3 |
ソースコード
import sys
from collections import defaultdict
input = sys.stdin.buffer.readline
ceil = lambda a, b: (a + b - 1) // b
def solve(M, P, A):
target = ceil(M, max(A))
d = defaultdict(int)
for a in A:
c = 1
while a:
if a % P:
break
a //= P
c += 1
d[c] = max(d[c], a)
d = dict(d)
if set(d.values()) == {1}:
return -1
MAX = 10000
dp = [1] * (MAX + max(d) + 1)
for i in range(MAX):
if dp[i] >= target:
return i + 1
for k, v in d.items():
dp[i + k] = max(dp[i + k], dp[i] * v)
N, M, P = map(int, input().split())
A = tuple(map(int, input().split()))
print(solve(M, P, A))