結果

問題 No.1668 Grayscale
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-09-03 22:53:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 426 ms / 4,000 ms
コード長 881 bytes
コンパイル時間 380 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 109,696 KB
最終ジャッジ日時 2024-05-09 06:03:38
合計ジャッジ時間 4,282 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,840 KB
testcase_01 AC 39 ms
52,096 KB
testcase_02 AC 39 ms
51,968 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 39 ms
52,224 KB
testcase_06 AC 296 ms
109,512 KB
testcase_07 AC 303 ms
109,696 KB
testcase_08 AC 202 ms
101,184 KB
testcase_09 AC 426 ms
109,460 KB
testcase_10 AC 350 ms
107,536 KB
testcase_11 AC 49 ms
62,080 KB
testcase_12 AC 64 ms
68,096 KB
testcase_13 AC 97 ms
78,028 KB
testcase_14 AC 147 ms
82,696 KB
testcase_15 AC 126 ms
80,884 KB
testcase_16 AC 107 ms
79,972 KB
testcase_17 AC 85 ms
77,436 KB
testcase_18 AC 39 ms
52,096 KB
testcase_19 AC 41 ms
52,096 KB
testcase_20 AC 68 ms
70,528 KB
testcase_21 AC 69 ms
70,144 KB
testcase_22 AC 39 ms
52,224 KB
testcase_23 AC 40 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

1668:
座圧したとする。
接触していなければ、unionしてもおk

dp[c] = 色cが神職の場合、色の最小数
とする。
色cが接触している色 & cよりも小さいやつ
の最大の値を記録しておけば、その色+1
で推移できる?

推移元としてokな左端は、+1

"""


import math
import sys
from sys import stdin

H,W,N = map(int,stdin.readline().split())

BC = [float("-inf")] * (H*W+1)

C = [list(map(int,stdin.readline().split())) for i in range(H)]

for i in range(H):
    for j in range(W):

        for x,y in [(i+1,j),(i-1,j),(i,j-1),(i,j+1)]:
            if 0 <= x < H and 0 <= y < W and C[x][y] < C[i][j]:
                BC[C[i][j]] = max(BC[C[i][j]] , C[x][y])

dp = [0] * (H*W+1)
nl = 0

for i in range(1,H*W+1):

    nl = max(nl , BC[i])
    #print (i,nl)
    dp[i] = dp[nl] + 1

#print (dp,BC)
print (dp[-1])
0