結果

問題 No.2744 Power! or +1
ユーザー tassei903tassei903
提出日時 2024-04-17 05:06:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,290 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 414,720 KB
最終ジャッジ日時 2024-04-17 18:33:15
合計ジャッジ時間 9,889 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 345 ms
121,728 KB
testcase_02 AC 161 ms
84,604 KB
testcase_03 AC 166 ms
87,808 KB
testcase_04 AC 279 ms
104,472 KB
testcase_05 WA -
testcase_06 AC 762 ms
193,024 KB
testcase_07 AC 46 ms
52,480 KB
testcase_08 AC 834 ms
158,424 KB
testcase_09 AC 64 ms
62,720 KB
testcase_10 AC 78 ms
67,584 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
    ik = i ** 2
    if ik >= n:
        ok = 1
        ik %= n
    
    for k in range(2, 30):
        if B >= 2 * 10**6:
            break
        if ok:
            g[i].append((ik+n, B))
            g[i+n].append((ik+n, B))
        else:
            g[i].append((ik, B))
            g[i+n].append((ik+n, B))
        if ik * i >= n:
            ok = 1
            ik = ik * i % n
        else:
            ik *= i
        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