結果

問題 No.2639 Longest Increasing Walk
ユーザー ThetaTheta
提出日時 2024-03-05 19:42:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 832 ms / 2,000 ms
コード長 1,201 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 47,696 KB
最終ジャッジ日時 2024-03-05 19:42:37
合計ジャッジ時間 11,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,112 KB
testcase_01 AC 30 ms
10,112 KB
testcase_02 AC 28 ms
10,112 KB
testcase_03 AC 32 ms
10,112 KB
testcase_04 AC 599 ms
40,064 KB
testcase_05 AC 743 ms
47,696 KB
testcase_06 AC 715 ms
46,952 KB
testcase_07 AC 819 ms
46,808 KB
testcase_08 AC 749 ms
47,316 KB
testcase_09 AC 832 ms
47,468 KB
testcase_10 AC 586 ms
27,496 KB
testcase_11 AC 480 ms
25,852 KB
testcase_12 AC 89 ms
12,544 KB
testcase_13 AC 638 ms
28,984 KB
testcase_14 AC 326 ms
20,860 KB
testcase_15 AC 29 ms
10,240 KB
testcase_16 AC 36 ms
10,496 KB
testcase_17 AC 298 ms
20,992 KB
testcase_18 AC 418 ms
22,908 KB
testcase_19 AC 115 ms
13,568 KB
testcase_20 AC 230 ms
17,920 KB
testcase_21 AC 480 ms
25,840 KB
testcase_22 AC 199 ms
15,744 KB
testcase_23 AC 30 ms
10,240 KB
testcase_24 AC 29 ms
10,240 KB
testcase_25 AC 32 ms
10,368 KB
testcase_26 AC 28 ms
10,240 KB
testcase_27 AC 34 ms
10,368 KB
testcase_28 AC 29 ms
10,112 KB
testcase_29 AC 28 ms
10,112 KB
testcase_30 AC 27 ms
10,112 KB
testcase_31 AC 28 ms
10,112 KB
testcase_32 AC 29 ms
10,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product
from math import inf, isinf
DIJ = ((0, 1), (1, 0), (0, -1), (-1, 0))


def main():
    H, W = map(int, input().split())

    def is_in_board(position: tuple[int, int]) -> bool:
        return 0 <= position[0] < H and 0 <= position[1] < W
    board = [list(map(int, input().split())) for _ in range(H)]

    coords = sorted([(board[h][w], h, w)
                    for h, w in product(range(H), range(W))])
    distances = [[-inf] * W for _ in range(H)]
    for coord in coords:
        if isinf(distances[coord[1]][coord[2]]):
            distances[coord[1]][coord[2]] = 1

        for dij in DIJ:
            neighbor = (coord[1] + dij[0], coord[2] + dij[1])
            if not is_in_board(neighbor):
                continue
            if board[coord[1]][coord[2]] >= board[neighbor[0]][neighbor[1]]:
                continue
            if distances[neighbor[0]][neighbor[1]
                                      ] < distances[coord[1]][coord[2]] + 1:
                distances[neighbor[0]][neighbor[1]
                                       ] = distances[coord[1]][coord[2]] + 1

    print(max(max(row) for row in distances))


if __name__ == "__main__":
    main()
0