結果

問題 No.1283 Extra Fee
ユーザー DrDrpilotDrDrpilot
提出日時 2022-03-15 13:08:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,019 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 135,704 KB
最終ジャッジ日時 2023-10-22 03:32:59
合計ジャッジ時間 25,743 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,404 KB
testcase_01 AC 39 ms
53,404 KB
testcase_02 AC 41 ms
53,404 KB
testcase_03 AC 40 ms
53,404 KB
testcase_04 AC 40 ms
53,404 KB
testcase_05 AC 39 ms
53,404 KB
testcase_06 AC 43 ms
53,404 KB
testcase_07 AC 40 ms
53,404 KB
testcase_08 AC 43 ms
55,452 KB
testcase_09 AC 43 ms
53,404 KB
testcase_10 AC 41 ms
53,404 KB
testcase_11 AC 298 ms
80,768 KB
testcase_12 AC 263 ms
80,728 KB
testcase_13 AC 196 ms
78,404 KB
testcase_14 AC 362 ms
84,812 KB
testcase_15 AC 482 ms
89,164 KB
testcase_16 AC 217 ms
79,180 KB
testcase_17 TLE -
testcase_18 AC 1,776 ms
128,444 KB
testcase_19 AC 1,531 ms
128,812 KB
testcase_20 AC 1,454 ms
125,148 KB
testcase_21 AC 1,456 ms
126,760 KB
testcase_22 AC 1,308 ms
120,808 KB
testcase_23 AC 1,217 ms
116,572 KB
testcase_24 AC 1,284 ms
124,656 KB
testcase_25 AC 1,595 ms
131,052 KB
testcase_26 AC 1,590 ms
130,492 KB
testcase_27 AC 1,610 ms
130,192 KB
testcase_28 AC 1,633 ms
130,712 KB
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n,m=map(int,input().split())
money=[[0]*n for _ in range(n)]
for _ in range(m):
    h,w,c=map(int,input().split())
    money[h-1][w-1]=c
inf=float('inf')
d=[[[inf]*2 for _ in range(n)] for _ in range(n)]
d[0][0][0]=0
q=[(0,0,0,0)]
while q:
    now_d,y,x,use=heapq.heappop(q)
    if d[y][x][use]<now_d:
        continue
    for dy,dx in [(1,0),(0,1),(-1,0),(0,-1)]:
        ny=y+dy;nx=x+dx
        if 0<=ny<n and 0<=nx<n:
            if money[ny][nx]==0:
                if d[ny][nx][use]>now_d+1:
                    d[ny][nx][use]=now_d+1
                    heapq.heappush(q,(now_d+1,ny,nx,use))
            else:
                cost=money[ny][nx]
                if d[ny][nx][use]>now_d+cost+1:
                    d[ny][nx][use]=now_d+cost+1
                    heapq.heappush(q,(now_d+cost+1,ny,nx,use))
                if use==0:
                    if d[ny][nx][1]>now_d+1:
                        d[ny][nx][1]=now_d+1
                        heapq.heappush(q,(now_d+1,ny,nx,1))
print(d[-1][-1][1])
0