結果

問題 No.2639 Longest Increasing Walk
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-02-20 14:27:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,584 KB
最終ジャッジ日時 2024-02-20 14:27:34
合計ジャッジ時間 5,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 33 ms
53,460 KB
testcase_04 AC 189 ms
98,584 KB
testcase_05 AC 182 ms
82,424 KB
testcase_06 AC 186 ms
82,168 KB
testcase_07 AC 190 ms
82,168 KB
testcase_08 AC 185 ms
82,680 KB
testcase_09 AC 203 ms
82,680 KB
testcase_10 AC 166 ms
81,272 KB
testcase_11 AC 157 ms
80,504 KB
testcase_12 AC 93 ms
76,496 KB
testcase_13 AC 177 ms
81,656 KB
testcase_14 AC 137 ms
78,596 KB
testcase_15 AC 37 ms
53,456 KB
testcase_16 AC 79 ms
76,240 KB
testcase_17 AC 140 ms
78,712 KB
testcase_18 AC 142 ms
79,364 KB
testcase_19 AC 96 ms
76,496 KB
testcase_20 AC 122 ms
78,084 KB
testcase_21 AC 160 ms
80,888 KB
testcase_22 AC 113 ms
77,316 KB
testcase_23 AC 64 ms
70,540 KB
testcase_24 AC 61 ms
70,668 KB
testcase_25 AC 71 ms
73,668 KB
testcase_26 AC 38 ms
55,592 KB
testcase_27 AC 73 ms
74,436 KB
testcase_28 AC 35 ms
53,460 KB
testcase_29 AC 38 ms
53,460 KB
testcase_30 AC 35 ms
53,460 KB
testcase_31 AC 35 ms
53,460 KB
testcase_32 AC 34 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]

indegs=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        for (di,dj) in [(1,0),(-1,0),(0,1),(0,-1)]:
            ni=i+di
            nj=j+dj
            if ni not in range(H) or nj not in range(W):continue
            if A[i][j]>A[ni][nj]:indegs[i][j]+=1

Q=[]
INF=int(1e18)
dist=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if indegs[i][j]==0:
            Q.append((i,j))
            dist[i][j]=1

while len(Q):
    i,j=Q.pop()
    for (di,dj) in [(1,0),(-1,0),(0,1),(0,-1)]:
        ni=i+di
        nj=j+dj
        if ni not in range(H) or nj not in range(W):continue
        if A[i][j]>=A[ni][nj]:continue
        indegs[ni][nj]-=1
        dist[ni][nj]=max(dist[ni][nj],dist[i][j]+1)
        if indegs[ni][nj]==0:Q.append((ni,nj))

ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,dist[i][j])
print(ans)
0