結果

問題 No.860 買い物
ユーザー mkawa2mkawa2
提出日時 2021-02-26 12:00:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 455 ms / 1,000 ms
コード長 1,339 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 82,580 KB
実行使用メモリ 109,056 KB
最終ジャッジ日時 2024-04-10 00:12:04
合計ジャッジ時間 5,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,140 KB
testcase_01 AC 37 ms
52,896 KB
testcase_02 AC 38 ms
54,300 KB
testcase_03 AC 37 ms
53,572 KB
testcase_04 AC 37 ms
52,884 KB
testcase_05 AC 37 ms
54,056 KB
testcase_06 AC 100 ms
77,964 KB
testcase_07 AC 423 ms
107,724 KB
testcase_08 AC 410 ms
107,916 KB
testcase_09 AC 426 ms
108,172 KB
testcase_10 AC 455 ms
108,016 KB
testcase_11 AC 266 ms
109,056 KB
testcase_12 AC 207 ms
107,132 KB
testcase_13 AC 379 ms
108,620 KB
testcase_14 AC 284 ms
107,268 KB
testcase_15 AC 370 ms
107,928 KB
testcase_16 AC 409 ms
107,856 KB
testcase_17 AC 198 ms
105,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def FI(): return float(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MF(): return map(float, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

from heapq import *

n=II()
to=[[] for _ in range(n+1)]
ans=0
for i in range(n):
    c,d=MI()
    ans+=c
    to[i].append((n,c))
    to[n].append((i,c))
    if i:
        to[i].append((i-1,d))
        to[i-1].append((i,d))

fin=[False]*(n+1)
fin[0]=True
hp=[]
for j,c in to[0]:
    heappush(hp,(c,j))
while hp:
    c,i=heappop(hp)
    if fin[i]:continue
    fin[i]=True
    ans+=c
    for j,c in to[i]:
        if fin[j]:continue
        heappush(hp,(c,j))

print(ans)
0