結果

問題 No.2146 2 Pows
ユーザー sotanishy
提出日時 2022-12-03 00:40:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 960 ms / 3,000 ms
コード長 795 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 173,384 KB
最終ジャッジ日時 2024-10-10 03:01:56
合計ジャッジ時間 19,238 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

def dijkstra(G, s):

    INF = 10**18
    dist = [INF] * len(G)
    dist[s] = 0
    pq = [(0, s)]
    while pq:
        d, v = heappop(pq)
        if d > dist[v]:
            continue
        for u, weight in G[v]:
            nd = d + weight
            if dist[u] > nd:
                dist[u] = nd
                heappush(pq, (nd, u))
    return dist

N, A, B, C = map(int, input().split())
dist = [10**18] * (2*N)
G = [[] for _ in range(2*N)]
for i in range(N):
    G[i].append((2*i%N, C))
    G[N+i].append((2*i%N, C))
    G[i].append((N+(i+1)%N, A+B))
    G[N+i].append((N+(i+1)%N, A))
dist = dijkstra(G, N+1)
ans = [10**18] * N
for i in range(N):
    ans[i] = min(dist[i], dist[N+i]) + A+B
print(*ans, sep="\n")
0