結果

問題 No.2744 Power! or +1
ユーザー tassei903tassei903
提出日時 2024-04-17 05:01:48
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,203 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 837,380 KB
最終ジャッジ日時 2024-04-17 18:33:10
合計ジャッジ時間 6,739 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 300 ms
122,080 KB
testcase_02 AC 137 ms
84,924 KB
testcase_03 AC 140 ms
88,120 KB
testcase_04 AC 303 ms
104,428 KB
testcase_05 WA -
testcase_06 AC 867 ms
193,320 KB
testcase_07 AC 39 ms
54,440 KB
testcase_08 AC 770 ms
158,392 KB
testcase_09 AC 51 ms
63,624 KB
testcase_10 AC 62 ms
68,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,a,b,c = map(int, input().split())

g = [[] for _ in range(n*2)]

g[n].append((0, 0))

fact = 1
fact_ = 0

for 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].append((n, a))
    ok = 0
    B = b**2
    for k in range(2, 30):
        if B >= 2 * 10**6:
            break
        if ok^1 and i ** k >= n:
            ok = 1
        if ok:
            g[i].append((pow(i, k, n)+n, B))
            g[i+n].append((pow(i, k, n)+n, B))
        else:
            g[i].append((i ** k, B))
            g[i+n].append((pow(i, k, n)+n, B))
        B *= b

    g[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_ = 1
    fact = fact * (i+1) % n

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

dist = dijkstra(g, 1, n*2)
print(dist[0])
0