結果

問題 No.2095 High Rise
ユーザー 👑 KazunKazun
提出日時 2022-10-07 22:02:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 887 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 172,660 KB
最終ジャッジ日時 2023-09-03 12:31:28
合計ジャッジ時間 9,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,272 KB
testcase_01 AC 67 ms
71,220 KB
testcase_02 AC 68 ms
71,360 KB
testcase_03 AC 65 ms
71,588 KB
testcase_04 AC 70 ms
71,408 KB
testcase_05 AC 67 ms
71,260 KB
testcase_06 AC 67 ms
71,488 KB
testcase_07 AC 68 ms
71,352 KB
testcase_08 AC 68 ms
71,332 KB
testcase_09 AC 66 ms
71,540 KB
testcase_10 AC 64 ms
71,360 KB
testcase_11 AC 67 ms
71,352 KB
testcase_12 AC 111 ms
78,084 KB
testcase_13 AC 109 ms
78,140 KB
testcase_14 AC 118 ms
78,064 KB
testcase_15 AC 109 ms
77,888 KB
testcase_16 AC 101 ms
78,484 KB
testcase_17 AC 346 ms
85,584 KB
testcase_18 AC 251 ms
82,684 KB
testcase_19 AC 149 ms
78,956 KB
testcase_20 AC 368 ms
88,156 KB
testcase_21 AC 631 ms
100,440 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

def solve():
    N,M=map(int,input().split())
    A=[]
    for _ in range(N):
        A.append(list(map(int,input().split())))

    if N==1:
        return 0

    inf=float("inf")
    T=[[inf]*M for _ in range(N)]
    U=[inf]*N; U[0]=0

    Q=[(0,0,-1)]
    while Q:
        cost,i,j=heappop(Q)

        if i==N-1:
            return cost

        if j==-1:
            Ai=A[i]; Ti=T[i]
            for k in range(M):
                if Ti[k]>cost+Ai[k]:
                    Ti[k]=cost+Ai[k]
                    heappush(Q,(Ti[k],i,k))
        else:
            alpha=cost+A[i+1][j]
            if T[i+1][j]>alpha:
                T[i+1][j]=alpha
                heappush(Q, (T[i+1][j],i+1,j))

            if U[i+1]>alpha:
                U[i+1]=alpha
                heappush(Q, (U[i+1],i+1,-1))

#==================================================
print(solve())
0