結果
問題 | No.2744 Power! or +1 |
ユーザー |
|
提出日時 | 2024-04-17 06:21:20 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,101 ms / 3,000 ms |
コード長 | 1,291 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 414,332 KB |
最終ジャッジ日時 | 2024-10-09 12:39:42 |
合計ジャッジ時間 | 9,251 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
n,a,b,c = map(int, input().split())g = [[] for _ in range(n*2)]g[n].append((0, 0))fact = 1fact_ = 0for i in range(n):g[i].append((i+1, a))if i < n-1:g[i+n].append((i+n+1, a))else:g[i+n].append((n, a))ok = 0B = b**2ik = i ** 2if ik >= n:ok = 1ik %= nfor k in range(2, 30):if B >= 2 * 10**6:breakif ok:g[i].append((ik+n, B))g[i+n].append((ik+n, B))else:g[i].append((ik, B))g[i+n].append((ik+n, B))if ik * i >= n:ok = 1ik = ik * i % nelse:ik *= iB *= bg[i+n].append((0, c))if fact_:g[i].append((fact + n, c))else:g[i].append((fact, c))if fact * (i+1) >= n:fact_ = 1fact = fact * (i+1) % nfrom heapq import *INF = 10**18def dijkstra(g, s, n):dist = [INF]*nhq = [(0, s)]dist[s] = 0while hq:d, v = heappop(hq)if dist[v]!=d:continuefor to, c in g[v]:if dist[v] + c < dist[to]:dist[to] = dist[v] + cheappush(hq, (dist[to], to))return distdist = dijkstra(g, 1, n*2)print(dist[0])