結果

問題 No.2639 Longest Increasing Walk
ユーザー KoiKoi
提出日時 2024-02-19 21:51:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 109,960 KB
最終ジャッジ日時 2024-02-19 21:51:48
合計ジャッジ時間 5,097 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,608 KB
testcase_01 AC 37 ms
55,608 KB
testcase_02 AC 35 ms
55,608 KB
testcase_03 AC 34 ms
55,608 KB
testcase_04 AC 118 ms
91,912 KB
testcase_05 AC 179 ms
109,960 KB
testcase_06 AC 178 ms
109,320 KB
testcase_07 AC 216 ms
109,192 KB
testcase_08 AC 208 ms
109,576 KB
testcase_09 AC 237 ms
109,960 KB
testcase_10 AC 163 ms
93,704 KB
testcase_11 AC 155 ms
92,552 KB
testcase_12 AC 79 ms
78,888 KB
testcase_13 AC 186 ms
95,624 KB
testcase_14 AC 133 ms
86,932 KB
testcase_15 AC 36 ms
55,608 KB
testcase_16 AC 63 ms
73,816 KB
testcase_17 AC 150 ms
85,128 KB
testcase_18 AC 126 ms
86,408 KB
testcase_19 AC 85 ms
79,508 KB
testcase_20 AC 112 ms
84,372 KB
testcase_21 AC 175 ms
92,424 KB
testcase_22 AC 119 ms
79,868 KB
testcase_23 AC 56 ms
66,400 KB
testcase_24 AC 55 ms
66,400 KB
testcase_25 AC 63 ms
70,976 KB
testcase_26 AC 39 ms
55,608 KB
testcase_27 AC 70 ms
73,056 KB
testcase_28 AC 40 ms
55,608 KB
testcase_29 AC 57 ms
55,608 KB
testcase_30 AC 41 ms
55,608 KB
testcase_31 AC 36 ms
55,608 KB
testcase_32 AC 41 ms
55,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H,W=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(H)]
G=[[] for _ in range(H*W)]
into_num=[0]*(H*W)
def xy_to_x_y(xy):
    return xy//W,xy%W
def x_y_to_xy(x,y):
    return x*W+y
dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(H):
    for j in range(W):
        for k in range(4):
            new_x=i+dx[k]
            new_y=j+dy[k]
            if(0<=new_x<H and 0<=new_y<W and A[i][j]<A[new_x][new_y]):
                ij=x_y_to_xy(i,j)
                new_xy=x_y_to_xy(new_x,new_y)
                G[ij].append(new_xy)
                into_num[new_xy]+=1
que=deque()
dp=[0]*(H*W)
for i in range(H*W):
    if(into_num[i]==0):
        que.append(i)
while len(que):
    p=que.popleft()
    for q in G[p]:
        dp[q]=max(dp[q],dp[p]+1)
        into_num[q]-=1
        if(into_num[q]==0):
            que.append(q)
print(max(dp)+1)
0