結果

問題 No.1330 Multiply or Divide
ユーザー rlangevin
提出日時 2024-04-17 12:09:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 512 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 81,924 KB
実行使用メモリ 106,856 KB
最終ジャッジ日時 2025-06-20 02:07:20
合計ジャッジ時間 5,165 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, P = map(int, input().split())
A = list(map(int, input().split()))
ma = max(A)

K, K2 = 100, 200
D = [1] * K
for i in range(N):
    cnt = 0
    while A[i] % P == 0:
        cnt += 1
        A[i] //= P
    D[cnt] = max(D[cnt], A[i])

inf = 10 ** 18
dp = [-inf] * K2
dp[0] = 1
for i in range(K2):
    if dp[i] * ma > M:
        print(i + 1)
        exit()
        
    for j in range(K):
        if i + j + 1 >= K2:
            break
        dp[i + j + 1] = max(dp[i + j + 1], dp[i] * D[j])
        
print(-1)
0