結果

問題 No.2639 Longest Increasing Walk
ユーザー 寝癖寝癖
提出日時 2024-02-19 22:59:51
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 970 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 267,984 KB
最終ジャッジ日時 2024-02-19 22:59:56
合計ジャッジ時間 4,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
62,404 KB
testcase_01 AC 41 ms
55,600 KB
testcase_02 AC 41 ms
55,600 KB
testcase_03 AC 42 ms
55,600 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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

to = [set() for _ in range(H*W)]
for x in range(H*W):
    i, j = divmod(x, W)
    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i+di, j+dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] > A[i][j]:
            to[x].add(ni*W+nj)

indegree = [0]*(H*W)
for x in range(H*W):
    for y in to[x]:
        indegree[y] += 1

B = [x for x in range(H*W) if indegree[x] == 0]
q = deque(B)
order = []
while q:
    x = q.popleft()
    order.append(x)
    for y in to[x]:
        indegree[y] -= 1
        if indegree[y] == 0:
            q.append(y)

ans = 0
for x in B:
    # xからスタート
    i = order.index(x)
    dist = [-1]*(H*W)
    dist[x] = 1
    while i < len(order):
        x = order[i]
        i += 1
        for y in to[x]:
            dist[y] = max(dist[y], dist[x]+1)
    ans = max(ans, max(dist))

print(ans)
    
0