結果
| 問題 | No.2639 Longest Increasing Walk |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:49:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 2,000 ms |
| コード長 | 1,079 bytes |
| 記録 | |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 87,300 KB |
| 最終ジャッジ日時 | 2025-02-19 16:51:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H,W;
cin>>H>>W;
vector A(H,vector<int>(W));
vector<tuple<int,int,int>>V;
for(int i=0;i<H;i++)for(int j=0;j<W;j++){
cin>>A[i][j];
V.push_back(make_tuple(A[i][j],i,j));
}
vector D(H,vector<int>(W));
sort(all(V));
for(auto[a,x,y]:V){
for(int i=0;i<4;i++){
int ex=x+dx[i],ey=y+dy[i];
if(ex>=0&&ex<H&&ey>=0&&ey<W&&A[x][y]<A[ex][ey]){
chmax(D[ex][ey],D[x][y]+1);
}
}
}
int ans=0;
for(int i=0;i<H;i++)for(int j=0;j<W;j++)chmax(ans,D[i][j]);
ans++;
cout<<ans<<"\n";
}