結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
Koi
|
| 提出日時 | 2024-02-19 21:50:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 882 bytes |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 82,508 KB |
| 実行使用メモリ | 110,836 KB |
| 最終ジャッジ日時 | 2024-09-29 01:49:00 |
| 合計ジャッジ時間 | 4,931 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 11 RE * 12 |
ソースコード
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//H,xy%H
def x_y_to_xy(x,y):
return x*H+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)
Koi