結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2022-01-15 09:51:13 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 408 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 102 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 29,148 KB |
最終ジャッジ日時 | 2025-06-20 01:38:48 |
合計ジャッジ時間 | 5,200 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
ソースコード
import sys from collections import defaultdict input = sys.stdin.buffer.readline def solve(M, P, A): target = M // max(A) + 1 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 target == 1: return 1 if max(A) != 1 else -1 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))