結果

問題 No.2639 Longest Increasing Walk
ユーザー 寝癖寝癖
提出日時 2024-02-19 23:18:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 63,016 KB
最終ジャッジ日時 2024-02-19 23:18:56
合計ジャッジ時間 10,157 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,112 KB
testcase_01 AC 28 ms
10,112 KB
testcase_02 AC 28 ms
10,112 KB
testcase_03 AC 28 ms
10,112 KB
testcase_04 AC 530 ms
50,176 KB
testcase_05 AC 798 ms
60,148 KB
testcase_06 AC 859 ms
61,720 KB
testcase_07 AC 899 ms
61,964 KB
testcase_08 AC 822 ms
59,896 KB
testcase_09 AC 916 ms
63,016 KB
testcase_10 AC 428 ms
32,148 KB
testcase_11 AC 380 ms
30,540 KB
testcase_12 AC 78 ms
12,860 KB
testcase_13 AC 474 ms
33,832 KB
testcase_14 AC 278 ms
27,576 KB
testcase_15 AC 28 ms
10,112 KB
testcase_16 AC 34 ms
10,496 KB
testcase_17 AC 265 ms
28,344 KB
testcase_18 AC 310 ms
28,060 KB
testcase_19 AC 101 ms
14,604 KB
testcase_20 AC 197 ms
19,404 KB
testcase_21 AC 379 ms
30,312 KB
testcase_22 AC 152 ms
18,576 KB
testcase_23 AC 29 ms
10,240 KB
testcase_24 AC 30 ms
10,112 KB
testcase_25 AC 31 ms
10,368 KB
testcase_26 AC 29 ms
10,112 KB
testcase_27 AC 32 ms
10,368 KB
testcase_28 AC 27 ms
10,112 KB
testcase_29 AC 29 ms
10,112 KB
testcase_30 AC 28 ms
10,112 KB
testcase_31 AC 28 ms
10,112 KB
testcase_32 AC 28 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
from sys import setrecursionlimit
setrecursionlimit(10**5)

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

@lru_cache(maxsize=None)
def dfs(i, j):
    # 4方向全てを見て、大きいものがなければ1を返す
    res = 1
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + dx, j + dy
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] > A[i][j]:
            res = max(res, dfs(ni, nj) + 1)

    return res

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(dfs(i, j), ans)

print(ans)
0