結果

問題 No.1668 Grayscale
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2021-09-03 23:40:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,006 ms / 4,000 ms
コード長 1,425 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 82,544 KB
実行使用メモリ 286,976 KB
最終ジャッジ日時 2024-05-09 07:49:35
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 36 ms
52,224 KB
testcase_03 AC 37 ms
52,608 KB
testcase_04 AC 37 ms
52,352 KB
testcase_05 AC 37 ms
52,736 KB
testcase_06 AC 675 ms
275,088 KB
testcase_07 AC 672 ms
275,088 KB
testcase_08 AC 206 ms
85,736 KB
testcase_09 AC 2,006 ms
286,976 KB
testcase_10 AC 932 ms
183,424 KB
testcase_11 AC 51 ms
63,616 KB
testcase_12 AC 77 ms
74,496 KB
testcase_13 AC 113 ms
79,616 KB
testcase_14 AC 310 ms
112,128 KB
testcase_15 AC 217 ms
94,208 KB
testcase_16 AC 162 ms
83,256 KB
testcase_17 AC 110 ms
79,104 KB
testcase_18 AC 38 ms
52,352 KB
testcase_19 AC 38 ms
52,480 KB
testcase_20 AC 65 ms
70,272 KB
testcase_21 AC 78 ms
74,752 KB
testcase_22 AC 38 ms
52,096 KB
testcase_23 AC 37 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w,n=map(int,input().split())
c=[[] for i in range(h)]
for i in range(h):
    c[i]=list(map(int,input().split()))
root=[[] for i in range(n+1)]

class topological_sort():
    #1-indexed
    #0-indexedはバグる
    def __init__(self,n):
        self.n=n
        self.root=[[] for _ in range(self.n+1)]
        self.deg=[0]*(self.n+1)
    def add(self,a,b):
        #有向辺 a->b の追加
        self.root[a].append(b)
        self.deg[b]+=1
    def const(self):
        #トポロジカルソートした結果を返す
        #不可能なら [] を返す
        deg2=self.deg[:]
        search=[]
        res=[]
        for i in range(1,self.n+1):
            if deg2[i]==0:search.append(i)
        while search:
            now=search.pop()
            res.append(now)
            for next in self.root[now]:
                deg2[next]-=1
                if deg2[next]==0:
                    search.append(next)
        if len(res)==self.n:
            return res
        return []

delta=[(1,0),(-1,0),(0,1),(0,-1)]

for i in range(h):
    for j in range(w):
        for di,dj in delta:
            if i+di<0 or i+di>=h or j+dj<0 or j+dj>=w:continue

            if c[i][j]>c[i+di][j+dj]:
                root[c[i+di][j+dj]].append((c[i][j],1))

dp=[1]*(n+1)
for i in range(1,n):
    root[i].append((i+1,0))
for x in range(n,0,-1):
    for y,cost in root[x]:
        dp[x]=max(dp[x],dp[y]+cost)
print(max(dp))

0