結果

問題 No.2095 High Rise
コンテスト
ユーザー roaris
提出日時 2022-10-07 21:58:36
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
(最新)
TLE  
(最初)
実行時間 1,605 ms / 2,000 ms
コード長 937 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 120 ms
コンパイル使用メモリ 85,728 KB
実行使用メモリ 133,844 KB
最終ジャッジ日時 2026-03-05 13:16:19
合計ジャッジ時間 12,306 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
from heapq import *

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
dist = [[[10**18]*M for _ in range(N)] for _ in range(2)]
pq = []

for i in range(M):
    dist[0][0][i] = 0
    heappush(pq, (0, 100*i))

while pq:
    d, xyf = heappop(pq)
    xy, f = divmod(xyf, 100)
    x, y = divmod(xy, 10**5)
    
    if dist[f][x][y]<d:
        continue
    
    for nx, ny in [(x, y-1), (x, y+1), (x+1, y)]:
        if 0<=nx<N and 0<=ny<M:
            if (nx, ny)==(x+1, y):
                w = A[nx][ny] if f==1 else A[x][y]+A[nx][ny]
                nf = 1
            else:
                w = 0
                nf = 0
            
            if dist[nf][nx][ny]>dist[f][x][y]+w:
                dist[nf][nx][ny] = dist[f][x][y]+w
                heappush(pq, (dist[nf][nx][ny], (nx*10**5+ny)*100+nf))

ans = min(min(dist[0][N-1]), min(dist[1][N-1]))
print(ans)
0