結果

問題 No.1283 Extra Fee
ユーザー AEnAEn
提出日時 2022-09-04 14:33:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,321 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 107,460 KB
最終ジャッジ日時 2024-04-29 15:10:02
合計ジャッジ時間 15,691 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
52,352 KB
testcase_01 AC 52 ms
52,352 KB
testcase_02 AC 41 ms
52,864 KB
testcase_03 AC 42 ms
52,608 KB
testcase_04 AC 42 ms
52,736 KB
testcase_05 AC 40 ms
52,352 KB
testcase_06 AC 42 ms
52,992 KB
testcase_07 AC 42 ms
52,864 KB
testcase_08 AC 44 ms
53,248 KB
testcase_09 AC 46 ms
53,120 KB
testcase_10 AC 43 ms
52,864 KB
testcase_11 AC 241 ms
78,796 KB
testcase_12 AC 172 ms
77,712 KB
testcase_13 AC 140 ms
77,184 KB
testcase_14 AC 204 ms
79,260 KB
testcase_15 AC 272 ms
81,612 KB
testcase_16 AC 147 ms
77,184 KB
testcase_17 AC 1,200 ms
105,436 KB
testcase_18 AC 824 ms
101,080 KB
testcase_19 AC 834 ms
101,328 KB
testcase_20 AC 808 ms
99,200 KB
testcase_21 AC 790 ms
99,432 KB
testcase_22 AC 702 ms
96,684 KB
testcase_23 AC 1,020 ms
89,780 KB
testcase_24 AC 1,137 ms
97,008 KB
testcase_25 AC 867 ms
101,752 KB
testcase_26 AC 875 ms
102,160 KB
testcase_27 AC 865 ms
101,024 KB
testcase_28 AC 842 ms
101,448 KB
testcase_29 AC 1,321 ms
107,460 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