結果

問題 No.1668 Grayscale
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-09-03 22:53:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 450 ms / 4,000 ms
コード長 881 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 110,872 KB
最終ジャッジ日時 2023-08-22 00:04:07
合計ジャッジ時間 5,499 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,208 KB
testcase_01 AC 69 ms
71,344 KB
testcase_02 AC 68 ms
71,364 KB
testcase_03 AC 71 ms
71,388 KB
testcase_04 AC 70 ms
71,524 KB
testcase_05 AC 69 ms
71,292 KB
testcase_06 AC 327 ms
110,548 KB
testcase_07 AC 327 ms
110,460 KB
testcase_08 AC 231 ms
102,384 KB
testcase_09 AC 450 ms
110,872 KB
testcase_10 AC 380 ms
108,928 KB
testcase_11 AC 77 ms
76,580 KB
testcase_12 AC 91 ms
77,140 KB
testcase_13 AC 120 ms
79,368 KB
testcase_14 AC 172 ms
84,280 KB
testcase_15 AC 149 ms
82,620 KB
testcase_16 AC 131 ms
81,312 KB
testcase_17 AC 110 ms
78,736 KB
testcase_18 AC 68 ms
71,516 KB
testcase_19 AC 69 ms
71,368 KB
testcase_20 AC 97 ms
77,448 KB
testcase_21 AC 97 ms
77,112 KB
testcase_22 AC 73 ms
71,368 KB
testcase_23 AC 72 ms
71,344 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