結果
問題 | No.2639 Longest Increasing Walk |
ユーザー |
|
提出日時 | 2024-02-20 14:08:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 919 bytes |
コンパイル時間 | 231 ms |
コンパイル使用メモリ | 82,448 KB |
実行使用メモリ | 128,432 KB |
最終ジャッジ日時 | 2024-09-29 03:42:57 |
合計ジャッジ時間 | 4,383 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 TLE * 1 -- * 27 |
ソースコード
import heapqH,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:continuedist[i][j]=-1Q=[]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:continuefor (di,dj) in [(1,0),(-1,0),(0,1),(0,-1)]:ni=pi+dinj=pj+djif ni not in range(H) or nj not in range(W):continueif A[pi][pj]>=A[ni][nj]:continueif dist[pi][pj]-1<dist[ni][nj]:dist[ni][nj]=dist[pi][pj]-1heapq.heappush(Q,(dist[ni][nj],(ni,nj)))ans=INFfor i in range(H):for j in range(W):ans=min(ans,dist[i][j])print(-ans)