結果

問題 No.1283 Extra Fee
ユーザー 👑 KazunKazun
提出日時 2020-11-07 00:07:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,598 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,212 KB
実行使用メモリ 136,212 KB
最終ジャッジ日時 2024-04-27 23:28:05
合計ジャッジ時間 17,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,740 KB
testcase_01 AC 43 ms
52,992 KB
testcase_02 AC 41 ms
52,952 KB
testcase_03 AC 40 ms
53,628 KB
testcase_04 AC 40 ms
53,564 KB
testcase_05 AC 40 ms
52,948 KB
testcase_06 AC 43 ms
54,588 KB
testcase_07 AC 41 ms
54,448 KB
testcase_08 AC 42 ms
54,516 KB
testcase_09 AC 41 ms
53,380 KB
testcase_10 AC 42 ms
54,188 KB
testcase_11 AC 227 ms
79,996 KB
testcase_12 AC 171 ms
79,620 KB
testcase_13 AC 140 ms
78,592 KB
testcase_14 AC 244 ms
84,072 KB
testcase_15 AC 321 ms
88,748 KB
testcase_16 AC 155 ms
78,660 KB
testcase_17 AC 1,466 ms
131,732 KB
testcase_18 AC 942 ms
128,116 KB
testcase_19 AC 971 ms
129,700 KB
testcase_20 AC 905 ms
125,488 KB
testcase_21 AC 902 ms
126,460 KB
testcase_22 AC 805 ms
120,236 KB
testcase_23 AC 1,169 ms
117,372 KB
testcase_24 AC 1,236 ms
125,764 KB
testcase_25 AC 977 ms
131,108 KB
testcase_26 AC 998 ms
130,832 KB
testcase_27 AC 989 ms
131,600 KB
testcase_28 AC 995 ms
130,420 KB
testcase_29 AC 1,598 ms
136,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys,heapq
    input=sys.stdin.readline

    N,M=map(int,input().split())
    inf=float("inf")

    F=[[1]*(N+1) for _ in range(N+1)]
    for _ in range(M):
        h,w,c=map(int,input().split())
        F[h][w]+=c

    V=[(1,0),(-1,0),(0,1),(0,-1)]

    Dist=[[[inf,inf] for _ in range(N+1)] for __ in range(N+1)]
    Dist[1][1][0]=0

    Q=[(0,(1,1,0))]
    heapq.heapify(Q)

    while Q:
        d,v=heapq.heappop(Q)

        i,j,m=v
        if d<Dist[i][j][m]:
            continue

        if i==j==N:
            break

        for (a,b) in V:
            if 1<=i+a<=N and 1<=j+b<=N:
                if d+F[i+a][j+b]<Dist[i+a][j+b][m]:
                    Dist[i+a][j+b][m]=d+F[i+a][j+b]
                    heapq.heappush(Q,(d+F[i+a][j+b],(i+a,j+b,m)))

                if m==0 and d+1<Dist[i+a][j+b][1]:
                    Dist[i+a][j+b][1]=d+1
                    heapq.heappush(Q,(d+1,(i+a,j+b,1)))

    print(min(Dist[N][N]))

if __name__=="__main__":
    main()
0