結果
問題 |
No.2039 Copy and Avoid
|
ユーザー |
![]() |
提出日時 | 2022-08-12 22:32:23 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 850 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,288 KB |
実行使用メモリ | 93,504 KB |
最終ジャッジ日時 | 2024-09-23 03:11:15 |
合計ジャッジ時間 | 6,609 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 30 |
ソースコード
from heapq import heappush, heappop import sys input = sys.stdin.readline def divisor(n): divisors = [] i = 1 while i * i < n: if n % i == 0: divisors.append(i) divisors.append(n // i) i += 1 if i * i == n: divisors.append(i) divisors.sort() return divisors N, M, A, B = map(int, input().split()) C = list(map(int, input().split())) dist = {} heap = [(0, N)] dist[N] = 0 while heap: d, n = heappop(heap) if n == 1: print(d-B) exit() if dist[n] < d: continue for m in divisor(n): if m == n: continue if any(c % m == 0 and c < n for c in C): continue nd = d + (n//m-1) * A + B if m not in dist or nd < dist[m]: dist[m] = nd heappush(heap, (nd, m)) print(-1)