結果

問題 No.1668 Grayscale
ユーザー hir355hir355
提出日時 2021-09-03 22:59:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,036 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 211,072 KB
最終ジャッジ日時 2024-05-09 06:18:06
合計ジャッジ時間 6,004 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 34 ms
51,968 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 AC 35 ms
52,096 KB
testcase_04 WA -
testcase_05 AC 34 ms
52,352 KB
testcase_06 WA -
testcase_07 AC 416 ms
210,944 KB
testcase_08 AC 134 ms
85,108 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 36 ms
52,352 KB
testcase_19 AC 35 ms
52,608 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 36 ms
52,096 KB
testcase_23 AC 35 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, n = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
inv = [0] * n
g = [[] for _ in range(n)]
for i in range(h):
    for j in range(w):
        if i < h - 1:
            if a[i][j] < a[i + 1][j]:
                g[a[i][j] - 1].append(a[i + 1][j] - 1)
                inv[a[i + 1][j] - 1] += 1
            elif a[i][j] > a[i + 1][j]:
                g[a[i + 1][j] - 1].append(a[i][j] - 1)
                inv[a[i][j] - 1] += 1
        if j < w - 1:
            if a[i][j] < a[i][j + 1]:
                g[a[i][j] - 1].append(a[i][j + 1] - 1)
                inv[a[i][j + 1] - 1] += 1
            elif a[i][j] > a[i][j + 1]:
                g[a[i][j + 1] - 1].append(a[i][j] - 1)
                inv[a[i][j] - 1] += 1
s = []
d = [0] * n
for i in range(n):
    if inv[i] == 0:
        s.append(i)
while s:
    p = s.pop()
    for node in g[p]:
        if d[node] < d[p] + 1:
            d[node] = d[p] + 1
        inv[node] -= 1
        if inv[node] == 0:
            s.append(node)
print(max(d) + 1)
0