結果

問題 No.2095 High Rise
ユーザー 👑 KazunKazun
提出日時 2022-10-07 22:06:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,393 ms / 2,000 ms
コード長 1,336 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 200,492 KB
最終ジャッジ日時 2023-09-03 12:43:44
合計ジャッジ時間 11,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,472 KB
testcase_01 AC 66 ms
71,536 KB
testcase_02 AC 67 ms
71,356 KB
testcase_03 AC 66 ms
71,392 KB
testcase_04 AC 65 ms
71,308 KB
testcase_05 AC 69 ms
71,500 KB
testcase_06 AC 65 ms
71,312 KB
testcase_07 AC 66 ms
71,316 KB
testcase_08 AC 64 ms
71,316 KB
testcase_09 AC 65 ms
71,480 KB
testcase_10 AC 65 ms
71,704 KB
testcase_11 AC 64 ms
71,448 KB
testcase_12 AC 120 ms
79,052 KB
testcase_13 AC 116 ms
78,196 KB
testcase_14 AC 124 ms
78,868 KB
testcase_15 AC 120 ms
79,016 KB
testcase_16 AC 114 ms
78,288 KB
testcase_17 AC 267 ms
87,912 KB
testcase_18 AC 214 ms
83,328 KB
testcase_19 AC 155 ms
80,980 KB
testcase_20 AC 297 ms
91,348 KB
testcase_21 AC 424 ms
106,520 KB
testcase_22 AC 1,393 ms
199,012 KB
testcase_23 AC 1,382 ms
200,492 KB
testcase_24 AC 1,327 ms
197,172 KB
testcase_25 AC 1,330 ms
196,880 KB
testcase_26 AC 1,362 ms
200,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
class Heap_Point:
    def __init__(self,x,d):
        self.d=d
        self.x=x

    def __str__(self):
        return "(point:{}, dist:{})".format(self.x,self.d)

    def __repr__(self):
        return str(self)

    def __lt__(self,other):
        return self.d<other.d

    def __iter__(self):
        yield from (self.x,self.d)

#==================================================
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=[Heap_Point((0,-1),0)]
    while Q:
        (i,j),cost=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,Heap_Point((i,k),Ti[k]))
        else:
            alpha=cost+A[i+1][j]
            if T[i+1][j]>alpha:
                T[i+1][j]=alpha
                heappush(Q, Heap_Point((i+1,j),T[i+1][j]))

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

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