結果

問題 No.2639 Longest Increasing Walk
ユーザー hato336
提出日時 2024-02-19 21:27:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,323 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 134,416 KB
最終ジャッジ日時 2024-09-29 01:23:06
合計ジャッジ時間 16,631 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline

#alist = list(map(int,input().split()))
#alist = []
#s = input()
h,w = map(int,input().split())
#for i in range(n):
#    alist.append(list(map(int,input().split())))
grid = [list(map(int,input().split())) for i in range(h)]
dp = [[1 for i in range(w)] for j in range(h)]
hq = []
for i in range(h):
    for j in range(w):
        heapq.heappush(hq,(grid[i][j],i,j))
dxy = [[-1,0],[1,0],[0,-1],[0,1]]
while hq:
    x,i,j = heapq.heappop(hq)
    for dx,dy in dxy:
        if 0 <= i+dx < h and 0 <= j+dy < w and grid[i+dx][j+dy] > x:
            dp[i+dx][j+dy] = max(dp[i+dx][j+dy],dp[i][j]+1)
ans = 0
for i in dp:
    ans = max(ans,max(i))
print(ans)
0