結果

問題 No.1283 Extra Fee
ユーザー AEnAEn
提出日時 2022-09-04 14:33:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,365 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 109,268 KB
最終ジャッジ日時 2023-08-11 23:52:50
合計ジャッジ時間 17,163 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,392 KB
testcase_01 AC 73 ms
71,356 KB
testcase_02 AC 75 ms
71,156 KB
testcase_03 AC 76 ms
71,144 KB
testcase_04 AC 75 ms
71,448 KB
testcase_05 AC 73 ms
71,224 KB
testcase_06 AC 75 ms
71,380 KB
testcase_07 AC 75 ms
71,224 KB
testcase_08 AC 76 ms
71,304 KB
testcase_09 AC 74 ms
71,372 KB
testcase_10 AC 76 ms
71,464 KB
testcase_11 AC 268 ms
80,732 KB
testcase_12 AC 196 ms
79,888 KB
testcase_13 AC 165 ms
79,072 KB
testcase_14 AC 227 ms
81,164 KB
testcase_15 AC 298 ms
82,184 KB
testcase_16 AC 170 ms
79,316 KB
testcase_17 AC 1,234 ms
107,648 KB
testcase_18 AC 848 ms
102,464 KB
testcase_19 AC 856 ms
102,164 KB
testcase_20 AC 834 ms
100,444 KB
testcase_21 AC 790 ms
100,840 KB
testcase_22 AC 739 ms
98,640 KB
testcase_23 AC 1,026 ms
91,416 KB
testcase_24 AC 1,157 ms
98,944 KB
testcase_25 AC 930 ms
102,948 KB
testcase_26 AC 909 ms
102,992 KB
testcase_27 AC 883 ms
102,364 KB
testcase_28 AC 857 ms
102,568 KB
testcase_29 AC 1,365 ms
109,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from heapq import heappop, heappush, heapify
    input = sys.stdin.readline

    N, M = map(int,input().split())

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

    xx = [1, 0, -1, 0]
    yy = [0, 1, 0, -1]

    dis0=[[float('inf')]*(N+1) for __ in range(N+1)]
    dis1=[[float('inf')]*(N+1) for __ in range(N+1)]
    dis0[1][1]=0

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

    while Q:
        d, v = heappop(Q)
        i , j, m = v
        if (m==0 and d<dis0[i][j]) or (m==1 and d<dis1[i][j]):
            continue
        if i==j==N:
            break
        for k in range(4):
            cx = i+xx[k]
            cy = j+yy[k]
            if 1<=cx<=N and 1<=cy<=N:
                c = d+F[cx][cy]
                if m==0 and c<dis0[cx][cy]:
                    dis0[cx][cy] = c
                    heappush(Q, (c,(cx,cy,0)))
                if m==1 and c<dis1[cx][cy]:
                    dis1[cx][cy] = c
                    heappush(Q, (c,(cx,cy,1)))
                if m==0 and d+1<dis1[cx][cy]:
                    dis1[cx][cy] = d+1
                    heappush(Q, (d+1,(cx,cy,1)))
    print(min(dis0[N][N], dis1[N][N]))
if __name__=="__main__":
    main()
0