結果

問題 No.1283 Extra Fee
ユーザー mkawa2mkawa2
提出日時 2020-11-07 11:40:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,414 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 10,840 KB
実行使用メモリ 59,276 KB
最終ジャッジ日時 2023-09-29 20:31:21
合計ジャッジ時間 6,963 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,884 KB
testcase_01 AC 19 ms
8,888 KB
testcase_02 AC 18 ms
8,808 KB
testcase_03 AC 19 ms
8,760 KB
testcase_04 AC 19 ms
8,896 KB
testcase_05 AC 19 ms
8,952 KB
testcase_06 AC 20 ms
8,900 KB
testcase_07 AC 19 ms
8,796 KB
testcase_08 AC 20 ms
8,808 KB
testcase_09 AC 20 ms
8,808 KB
testcase_10 AC 19 ms
8,764 KB
testcase_11 AC 172 ms
11,040 KB
testcase_12 AC 197 ms
11,656 KB
testcase_13 AC 131 ms
10,688 KB
testcase_14 AC 524 ms
17,060 KB
testcase_15 AC 846 ms
22,004 KB
testcase_16 AC 187 ms
11,400 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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