結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-09-25 14:52:00 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 814 bytes |
| コンパイル時間 | 76 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 314,496 KB |
| 最終ジャッジ日時 | 2024-07-05 12:05:38 |
| 合計ジャッジ時間 | 4,003 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 TLE * 1 -- * 44 |
ソースコード
import heapq
import bisect
from collections import defaultdict
inf = 10 ** 18
N, M, P = map(int, input().split())
A = list(map(int, input().split()))
last = max(A)
if last > M:
print(1)
exit()
dist = defaultdict(lambda: inf)
edge = defaultdict(lambda: inf)
found = False
for a in A:
cnt = 1
while a % P == 0:
a //= P
cnt += 1
if a == 1:
continue
edge[a] = min(edge[a], cnt)
found = True
if not found:
print(-1)
exit()
que = [(0, 1)]
dist[1] = 0
while que:
ds, s = heapq.heappop(que)
if dist[s] < ds:
continue
if s * last > M:
print(ds + 1)
break
for t, dt in edge.items():
next = s * t
if dist[next] > ds + dt:
dist[next] = ds + dt
heapq.heappush(que, (ds + dt, next))
tktk_snsn