結果
問題 |
No.2639 Longest Increasing Walk
|
ユーザー |
![]() |
提出日時 | 2024-06-02 18:23:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,997 ms / 2,000 ms |
コード長 | 732 bytes |
コンパイル時間 | 394 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 387,832 KB |
最終ジャッジ日時 | 2024-12-23 10:20:07 |
合計ジャッジ時間 | 8,770 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
from sys import setrecursionlimit import pypyjit setrecursionlimit(10 ** 7) pypyjit.set_param('max_unroll_recursion=-1') H, W = map(int, input().split()) A = sum([list(map(int, input().split())) for _ in range(H)], []) memo = {} def dp(x): # (i, j)からスタートして何マス歩けるか if x in memo: return memo[x] i, j = divmod(x, W) res = 1 for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]: ni, nj = i+dx, j+dy if not (0 <= ni < H and 0 <= nj < W): continue if A[i*W+j] < A[ni*W+nj]: res = max(res, dp(ni*W+nj)+1) memo[x] = res return res ans = 0 for i in range(H): for j in range(W): ans = max(ans, dp(i*W+j)) print(ans)