結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:34:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 816 bytes |
| コンパイル時間 | 2,069 ms |
| コンパイル使用メモリ | 206,816 KB |
| 最終ジャッジ日時 | 2025-02-19 16:41:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H,W;
cin>>H>>W;
vector A(H,vector(W,0));
vector V(0,array<int,3>());
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>A[i][j];
V.push_back({A[i][j],i,j});
}
}
sort(V.begin(),V.end());
vector dp(H,vector(W,1));
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
auto bound_ok=[&](int x,int y){
return x>=0&&x<H&&y>=0&&y<W;
};
for(int i=0;i<H*W;i++){
auto [v,x,y]=V[i];
for(int j=0;j<4;j++){
int x2=x+dx[j],y2=y+dy[j];
if(bound_ok(x2,y2)&&A[x2][y2]<v){
dp[x][y]=max(dp[x][y],dp[x2][y2]+1);
}
}
}
int ans=0;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++)ans=max(ans,dp[i][j]);
}
cout<<ans<<'\n';
}