結果

問題 No.1668 Grayscale
コンテスト
ユーザー Kude
提出日時 2021-09-03 22:43:00
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 671 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,801 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 211,292 KB
最終ジャッジ日時 2026-10-04 03:02:04
合計ジャッジ時間 4,709 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 8 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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