結果

問題 No.2639 Longest Increasing Walk
ユーザー ntudantuda
提出日時 2024-02-23 00:00:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 964 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 108,532 KB
最終ジャッジ日時 2024-02-23 00:00:44
合計ジャッジ時間 5,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 37 ms
53,456 KB
testcase_04 AC 134 ms
106,100 KB
testcase_05 AC 162 ms
108,532 KB
testcase_06 AC 170 ms
107,764 KB
testcase_07 AC 202 ms
107,764 KB
testcase_08 AC 175 ms
107,380 KB
testcase_09 AC 225 ms
106,740 KB
testcase_10 AC 169 ms
94,708 KB
testcase_11 AC 154 ms
92,660 KB
testcase_12 AC 106 ms
77,708 KB
testcase_13 AC 167 ms
94,784 KB
testcase_14 AC 148 ms
84,972 KB
testcase_15 AC 40 ms
53,460 KB
testcase_16 AC 76 ms
73,332 KB
testcase_17 AC 153 ms
83,708 KB
testcase_18 AC 138 ms
84,260 KB
testcase_19 AC 112 ms
78,648 KB
testcase_20 AC 132 ms
83,968 KB
testcase_21 AC 159 ms
92,788 KB
testcase_22 AC 116 ms
79,688 KB
testcase_23 AC 44 ms
59,684 KB
testcase_24 AC 44 ms
59,684 KB
testcase_25 AC 60 ms
68,652 KB
testcase_26 AC 37 ms
53,460 KB
testcase_27 AC 65 ms
71,260 KB
testcase_28 AC 38 ms
53,460 KB
testcase_29 AC 37 ms
53,460 KB
testcase_30 AC 37 ms
53,460 KB
testcase_31 AC 37 ms
53,460 KB
testcase_32 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
E = [[] for _ in range(H * W)]
D = [0] * (H * W)
for h in range(H):
    for w in range(W):
        if h > 0:
            if A[h][w] > A[h - 1][w]:
                E[w + W * (h - 1)].append(w + W * h)
                D[w + W * h] += 1
            if A[h][w] < A[h - 1][w]:
                E[w + W * h].append(w + W * (h - 1))
                D[w + W * (h - 1)] += 1
        if w > 0:
            if A[h][w] > A[h][w - 1]:
                E[w - 1 + W * h].append(w + W * h)
                D[w + W * h] += 1
            if A[h][w] < A[h][w - 1]:
                E[w + W * h].append(w - 1 + W * h)
                D[w - 1 + W * h] += 1

X = [1] * (H * W)
Q = []
for i in range(H * W):
    if D[i] == 0:
        Q.append(i)
while Q:
    a = Q.pop()
    for b in E[a]:
        X[b] = max(X[b],X[a]+1)
        D[b] -= 1
        if D[b] == 0:
            Q.append(b)
print(max(X))

0