結果

問題 No.1668 Grayscale
ユーザー Kude
提出日時 2021-09-03 22:43:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 671 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 203,676 KB
最終ジャッジ日時 2024-12-15 15:42:47
合計ジャッジ時間 4,915 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

h, w, n = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(h)]
for i in range(h):
    for j in range(w):
        c[i][j] -= 1

to = [[] for _ in range(n)]
for i in range(h - 1):
    for j in range(w):
        x = c[i][j]
        y = c[i + 1][j]
        if x < y:
            to[x].append(y)
        elif x > y:
            to[y].append(x)
for i in range(h):
    for j in range(w - 1):
        x = c[i][j]
        y = c[i][j + 1]
        if x < y:
            to[x].append(y)
        elif x > y:
            to[y].append(x)

dp = [0] * n
for i in range(n):
    for j in to[i]:
        dp[j] = max(dp[j], dp[i] + 1)
ans = max(dp)
print(ans + 1)
0