結果

問題 No.2744 Power! or +1
ユーザー PNJPNJ
提出日時 2024-04-20 13:37:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,164 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 121,640 KB
最終ジャッジ日時 2024-04-20 13:37:51
合計ジャッジ時間 3,907 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 494 ms
119,900 KB
testcase_01 AC 368 ms
107,640 KB
testcase_02 AC 128 ms
82,744 KB
testcase_03 AC 144 ms
85,056 KB
testcase_04 AC 103 ms
80,196 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 486 ms
121,640 KB
testcase_09 AC 49 ms
60,800 KB
testcase_10 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def dijkstra(s, n, edge):
    dist = [float("Inf")]*n
    dist[s] = 0
    hq = [[0,s]]
    heapq.heapify(hq)
    while len(hq) > 0:
        d,i = heapq.heappop(hq)
        if dist[i] < d:
            continue
        for j,d_1 in edge[i]:
            if dist[j] > (dist[i] + d_1):
                dist[j] = dist[i] + d_1
                heapq.heappush(hq, [dist[j],j])
    return dist

N,A,B,C = map(int,input().split())
fact = [1]
for i in range(1,N+1):
  f = fact[-1]*i
  f %= N
  fact.append(f)

dist = [-1 for i in range(N+1)]
G = [[] for i in range(N+1)]
G[N].append((0,C))
for x in range(1,N):
  G[x].append(((x+1)%N,A))
for x in range(2,N):
  for k in range(2,N+1):
    if pow(B,k) > 10**18:
      break
    xx = pow(x,k)
    if xx % N == 0:
      G[x].apppend((0,pow(B,k)))
      break
    if xx >= N:
      G[x].append((N,pow(B,k)))
      break
    G[x].append((xx,pow(B,k)))
  if fact[x] == 0:
    G[x].append((0,C))
    continue
  if x >= 9:
    G[x].append((N,C))
  else:
    f = 1
    for i in range(1,x+1):
      f *= i
    if f > N:
      G[x].append((N,C))
    else:
      G[x].append((f,C))

dist = dijkstra(1, N+1, G)
print(dist[0])
0