結果
| 問題 | 
                            No.2639 Longest Increasing Walk
                             | 
                    
| コンテスト | |
| ユーザー | 
                             umezo
                         | 
                    
| 提出日時 | 2024-02-20 04:44:10 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 139 ms / 2,000 ms | 
| コード長 | 848 bytes | 
| コンパイル時間 | 2,027 ms | 
| コンパイル使用メモリ | 200,080 KB | 
| 最終ジャッジ日時 | 2025-02-19 17:53:48 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int A[510][510];
int dp[510][510];
int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int h,w;
  cin>>h>>w;
  set<pair<int,pair<int,int>>> s;
  rep(i,h) rep(j,w){
    cin>>A[i][j];
    s.insert({A[i][j],{i,j}});
  }
  for(auto x:s){
    int a=x.first;
    int i=x.second.first,j=x.second.second;
    bool b=false;
    rep(k,4){
      int ni=i+dh[k],nj=j+dw[k];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      if(A[ni][nj]<a){
        dp[i][j]=max(dp[i][j],dp[ni][nj]+1);
        b=true;
      }
    }
    if(b==false) dp[i][j]=1;
  }
  int ans=0;
  rep(i,h) rep(j,w) ans=max(ans,dp[i][j]);
  cout<<ans<<endl;
  
  return 0;
}
            
            
            
        
            
umezo