結果

問題 No.2146 2 Pows
ユーザー sotanishysotanishy
提出日時 2022-12-03 00:40:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 843 ms / 3,000 ms
コード長 795 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,288 KB
実行使用メモリ 173,640 KB
最終ジャッジ日時 2024-04-18 09:48:52
合計ジャッジ時間 16,623 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,608 KB
testcase_01 AC 36 ms
52,992 KB
testcase_02 AC 40 ms
52,608 KB
testcase_03 AC 44 ms
52,864 KB
testcase_04 AC 38 ms
52,736 KB
testcase_05 AC 625 ms
163,584 KB
testcase_06 AC 809 ms
170,120 KB
testcase_07 AC 497 ms
173,272 KB
testcase_08 AC 789 ms
173,640 KB
testcase_09 AC 843 ms
172,804 KB
testcase_10 AC 100 ms
77,412 KB
testcase_11 AC 108 ms
77,176 KB
testcase_12 AC 107 ms
78,152 KB
testcase_13 AC 100 ms
77,832 KB
testcase_14 AC 102 ms
77,312 KB
testcase_15 AC 113 ms
81,824 KB
testcase_16 AC 498 ms
133,964 KB
testcase_17 AC 479 ms
136,692 KB
testcase_18 AC 237 ms
103,012 KB
testcase_19 AC 678 ms
153,216 KB
testcase_20 AC 700 ms
157,204 KB
testcase_21 AC 344 ms
106,864 KB
testcase_22 AC 767 ms
162,692 KB
testcase_23 AC 589 ms
150,272 KB
testcase_24 AC 534 ms
137,220 KB
testcase_25 AC 622 ms
144,700 KB
testcase_26 AC 789 ms
166,544 KB
testcase_27 AC 626 ms
153,216 KB
testcase_28 AC 577 ms
139,388 KB
testcase_29 AC 241 ms
100,516 KB
testcase_30 AC 504 ms
132,128 KB
testcase_31 AC 536 ms
152,576 KB
testcase_32 AC 230 ms
88,928 KB
testcase_33 AC 492 ms
141,532 KB
権限があれば一括ダウンロードができます

ソースコード

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