結果

問題 No.2639 Longest Increasing Walk
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-02-20 14:08:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 919 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 127,628 KB
最終ジャッジ日時 2024-02-20 14:08:07
合計ジャッジ時間 4,696 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
60,264 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 256 ms
118,648 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
H,W=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
v=[]
for i in range(H):
    for j in range(H):
        v.append((A[i],i,j))
v.sort()

INF=int(1e18)
dist=[[INF for _ in range(W)] for _ in range(H)]

for (_,i,j) in v:
    if dist[i][j]<INF:continue
    dist[i][j]=-1
    Q=[]
    heapq.heapify(Q)
    heapq.heappush(Q,(dist[i][j],(i,j)))
    
    while len(Q):
        d,(pi,pj)=heapq.heappop(Q)
        if dist[pi][pj]!=d:continue
        for (di,dj) in [(1,0),(-1,0),(0,1),(0,-1)]:
            ni=pi+di
            nj=pj+dj
            if ni not in range(H) or nj not in range(W):continue
            if A[pi][pj]>=A[ni][nj]:continue
            if dist[pi][pj]-1<dist[ni][nj]:
                dist[ni][nj]=dist[pi][pj]-1
                heapq.heappush(Q,(dist[ni][nj],(ni,nj)))
ans=INF
for i in range(H):
    for j in range(W):
        ans=min(ans,dist[i][j])
print(-ans)
0