結果
| 問題 |
No.2146 2 Pows
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-15 19:31:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,132 ms / 3,000 ms |
| コード長 | 1,067 bytes |
| コンパイル時間 | 595 ms |
| コンパイル使用メモリ | 82,820 KB |
| 実行使用メモリ | 173,576 KB |
| 最終ジャッジ日時 | 2025-07-15 19:31:59 |
| 合計ジャッジ時間 | 22,203 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 |
ソースコード
from heapq import *
INF = 10**18
def dijkstra(g, s, n):
dist = [INF]*n
hq = [(0, s)]
dist[s] = 0
while hq:
d, v = heappop(hq)
if dist[v]!=d:
continue
for to, c in g[v]:
if dist[v] + c < dist[to]:
dist[to] = dist[v] + c
heappush(hq, (dist[to], to))
return dist
n, a, b, C = map(int, input().split())
g = [[] for i in range(n * 2)]
for i in range(n):
g[i].append(((i * 2 + 1) % n + n, a + b + C))
g[i + n].append(((i + 1) % n + n, a))
g[i + n].append((i, 0))
g[i].append((i * 2 % n, C))
dist = [INF] * (n * 2)
hq = []
for i in range(1, n + 1):
heappush(hq, (a * i + b, i % n + n))
dist[i % n + n] = a * i + b
# print(dist)
while hq:
d, v = heappop(hq)
# print(d, v)
if dist[v]!=d:
continue
for to, c in g[v]:
if dist[v] + c < dist[to]:
# print(d, v, to, dist[v], c)
dist[to] = dist[v] + c
heappush(hq, (dist[to], to))
# print(dist)
for i in range(n):
print(dist[i])