問題一覧 > 通常問題

No.2639 Longest Increasing Walk

レベル : / AI推定難易度 : 875 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 113
作問者 : noya2 / テスター : shobonvip ponjuice
お気に入りにしたユーザー ProblemId : 10626 / 自分の提出
問題文最終更新日: 2024-02-19 00:42:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
traP 作問ハッカソンコンテスト 002(day2) (順位表) の他の問題:

Problem Statement

There is a grid with $H$ rows and $W$ columns. The cell in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i,j)$. The value $A_{i,j}$ is written in cell $(i,j)$.

A sequence of cells $((i_1,j_1),(i_2,j_2),\dots ,(i_L,j_L))$ of length $L$ is called an Increasing Walk if all of the following conditions hold.

  • For $k=1,2,\dots ,L-1$, cells $(i_k,j_k),(i_{k+1},j_{k+1})$ are adjacent by an edge. That is, $\lvert i_k-i_{k+1}\rvert + \lvert j_k-j_{k+1}\rvert =1$ holds.
  • For $k=1,2,\dots ,L-1$, the value written in cell $(i_{k+1},j_{k+1})$ is strictly greater than the value written in cell $(i_k,j_k)$. That is, $A_{i_k,j_k}\lt A_{i_{k+1},j_{k+1}}$ holds.

Find the maximum possible length of an Increasing Walk. (It can be shown that the maximum exists.)

Constraints

  • All input values are integers.
  • $1\le H,W\le 500$
  • $1\le A_{i,j}\le 10^9\ (1\le i\le H, 1\le j\le W)$

Input

$H$ $W$
$A_{1,1}$ $A_{1,2}$ $\dots$ $A_{1,W}$
$\vdots$
$A_{H,1}$ $A_{H,2}$ $\dots$ $A_{H,W}$

Output

Output the maximum possible length of an Increasing Walk.

Sample

Sample 1
Input
2 3
1 2 4
3 3 4
Output
4

The sequence of cells $((1,1),(1,2),(2,2),(2,3))$ is an Increasing Walk of length $4$.

Sample 2
Input
2 2
1 1
1 1
Output
1

Sample 3
Input
4 4
3 1 4 1
5 9 2 6
5 3 5 8
9 7 9 3
Output
4

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。