結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 257 ms
122,036 KB
testcase_02 AC 119 ms
84,660 KB
testcase_03 AC 118 ms
87,532 KB
testcase_04 AC 256 ms
104,560 KB
testcase_05 WA -
testcase_06 AC 768 ms
193,348 KB
testcase_07 AC 35 ms
55,140 KB
testcase_08 AC 672 ms
158,648 KB
testcase_09 AC 43 ms
63,620 KB
testcase_10 AC 53 ms
69,548 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
    for k in range(2, 30):
        if b ** k >= 2 * 10**6:
            break
        if ok^1 and i ** k >= n:
            ok = 1
        if ok:
            g[i].append((pow(i, k, n)+n, b**k))
            g[i+n].append((pow(i, k, n)+n, b**k))
        else:
            g[i].append((i ** k, b**k))
            g[i+n].append((pow(i, k, n)+n, b**k))

    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