結果

問題 No.1668 Grayscale
ユーザー noiminoimi
提出日時 2021-08-31 01:08:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 250,796 KB
最終ジャッジ日時 2024-05-09 00:51:30
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 40 ms
52,708 KB
testcase_03 AC 39 ms
53,536 KB
testcase_04 WA -
testcase_05 AC 40 ms
53,324 KB
testcase_06 AC 687 ms
250,332 KB
testcase_07 WA -
testcase_08 AC 307 ms
159,896 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 40 ms
54,088 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 40 ms
53,308 KB
testcase_23 AC 40 ms
53,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
def solve():
    h, w, n = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    v = [a[i][j] for i in range(h) for j in range(w)]
    v = list(set(v))
    
    for i in range(h):
        for j in range(w):
            a[i][j] = bisect.bisect_left(v, a[i][j])
    
    dp = [0 for _ in range(n + 1)]
    
    dp[0] = 1
    
    nxt = [n for _ in range(n + 1)]
    
    for i in range(h - 1):
        for j in range(w):
            x = min(a[i][j], a[i + 1][j])
            y = max(a[i][j], a[i + 1][j])
            if x != y:
                nxt[x] = min(nxt[x], y)
    
    for i in range(h):
        for j in range(w - 1):
            x = min(a[i][j], a[i][j + 1])
            y = max(a[i][j], a[i][j + 1])
            if x != y:
                nxt[x] = min(nxt[x], y)
    
    for i in range(n):
        dp[i + 1] = max(dp[i + 1], dp[i])
        if nxt[i] != n:
            dp[nxt[i]] = max(dp[nxt[i]], dp[i] + 1)
            
    print(dp[n])
    


if __name__ == '__main__':
    solve()
0