結果
| 問題 |
No.1668 Grayscale
|
| コンテスト | |
| ユーザー |
taiga0629kyopro
|
| 提出日時 | 2021-09-03 23:40:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,757 ms / 4,000 ms |
| コード長 | 1,425 bytes |
| コンパイル時間 | 434 ms |
| コンパイル使用メモリ | 82,420 KB |
| 実行使用メモリ | 287,032 KB |
| 最終ジャッジ日時 | 2024-12-15 18:45:48 |
| 合計ジャッジ時間 | 6,684 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
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))
taiga0629kyopro