結果

問題 No.1668 Grayscale
ユーザー noiminoimi
提出日時 2021-08-31 01:23:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 860 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 98,176 KB
最終ジャッジ日時 2024-05-09 00:52:37
合計ジャッジ時間 16,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 29 ms
10,880 KB
testcase_04 WA -
testcase_05 AC 29 ms
10,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,477 ms
19,584 KB
testcase_09 AC 3,402 ms
70,400 KB
testcase_10 AC 2,317 ms
50,432 KB
testcase_11 AC 31 ms
11,008 KB
testcase_12 AC 35 ms
11,136 KB
testcase_13 AC 201 ms
14,464 KB
testcase_14 AC 607 ms
22,016 KB
testcase_15 AC 395 ms
17,664 KB
testcase_16 AC 288 ms
15,872 KB
testcase_17 AC 144 ms
13,184 KB
testcase_18 AC 30 ms
11,008 KB
testcase_19 AC 29 ms
10,880 KB
testcase_20 AC 33 ms
10,880 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
def solve():
    h, w, n = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    
    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