結果

問題 No.1283 Extra Fee
ユーザー mkawa2mkawa2
提出日時 2020-11-07 11:40:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,677 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 82,488 KB
実行使用メモリ 121,848 KB
最終ジャッジ日時 2024-04-27 23:35:52
合計ジャッジ時間 18,198 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
56,052 KB
testcase_01 AC 42 ms
55,940 KB
testcase_02 AC 40 ms
56,032 KB
testcase_03 AC 38 ms
54,700 KB
testcase_04 AC 41 ms
55,140 KB
testcase_05 AC 40 ms
56,388 KB
testcase_06 AC 43 ms
56,104 KB
testcase_07 AC 40 ms
55,784 KB
testcase_08 AC 42 ms
57,112 KB
testcase_09 AC 41 ms
56,688 KB
testcase_10 AC 42 ms
55,792 KB
testcase_11 AC 206 ms
80,236 KB
testcase_12 AC 213 ms
80,212 KB
testcase_13 AC 149 ms
78,884 KB
testcase_14 AC 277 ms
82,856 KB
testcase_15 AC 358 ms
85,556 KB
testcase_16 AC 172 ms
79,736 KB
testcase_17 AC 1,549 ms
119,300 KB
testcase_18 AC 1,136 ms
107,332 KB
testcase_19 AC 1,138 ms
107,672 KB
testcase_20 AC 1,029 ms
104,904 KB
testcase_21 AC 1,029 ms
106,408 KB
testcase_22 AC 966 ms
103,272 KB
testcase_23 AC 928 ms
103,964 KB
testcase_24 AC 927 ms
103,876 KB
testcase_25 AC 1,131 ms
108,596 KB
testcase_26 AC 1,147 ms
108,324 KB
testcase_27 AC 1,172 ms
108,364 KB
testcase_28 AC 1,135 ms
107,720 KB
testcase_29 AC 1,677 ms
121,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

# input=sys.stdin.buffer.readline
input=sys.stdin.readline

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return input()[:-1]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

from heapq import *

def inval(ni,nj,h,w):
    if ni<0 or ni>=h or nj<0 or nj>=w:return True
    return False

inf=10**16
n,m=MI()
cc=[[0]*n for _ in range(n)]
for _ in range(m):
    i,j,c=MI()
    cc[i-1][j-1]=c

hp=[]
dd=[[[inf]*2 for _ in range(n)]for _ in range(n)]
dd[0][0][0]=0
heappush(hp,(0,0,0,0))
while hp:
    d,i,j,k=heappop(hp)
    if d>dd[i][j][k]:continue
    for di,dj in dij:
        ni,nj=i+di,j+dj
        if inval(ni,nj,n,n):continue
        nd=d+cc[ni][nj]+1
        if nd<dd[ni][nj][k]:
            dd[ni][nj][k]=nd
            heappush(hp,(nd,ni,nj,k))
        if k==0 and d+1<dd[ni][nj][1]:
            dd[ni][nj][1]=d+1
            heappush(hp,(d+1,ni,nj,1))

print(dd[n-1][n-1][1])
0