結果

問題 No.2095 High Rise
ユーザー roarisroaris
提出日時 2022-10-07 21:58:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 937 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 131,328 KB
最終ジャッジ日時 2023-09-03 02:03:28
合計ジャッジ時間 18,990 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,220 KB
testcase_01 AC 75 ms
70,868 KB
testcase_02 AC 73 ms
71,096 KB
testcase_03 AC 74 ms
71,220 KB
testcase_04 AC 77 ms
71,096 KB
testcase_05 AC 72 ms
71,348 KB
testcase_06 AC 71 ms
71,280 KB
testcase_07 AC 74 ms
71,220 KB
testcase_08 AC 75 ms
71,272 KB
testcase_09 AC 75 ms
71,296 KB
testcase_10 AC 78 ms
71,384 KB
testcase_11 AC 77 ms
71,168 KB
testcase_12 AC 182 ms
78,540 KB
testcase_13 AC 162 ms
78,468 KB
testcase_14 AC 186 ms
79,800 KB
testcase_15 AC 173 ms
78,472 KB
testcase_16 AC 139 ms
77,956 KB
testcase_17 AC 384 ms
83,576 KB
testcase_18 AC 301 ms
82,172 KB
testcase_19 AC 205 ms
79,568 KB
testcase_20 AC 447 ms
85,184 KB
testcase_21 AC 703 ms
91,556 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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