結果

問題 No.2639 Longest Increasing Walk
ユーザー noya2
提出日時 2024-02-12 20:58:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 3,121 ms
コンパイル使用メモリ 255,764 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 01:11:45
合計ジャッジ時間 5,636 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<bits/stdc++.h>
using namespace std;
const array<int,4> dx = {1,0,-1,0};
const array<int,4> dy = {0,1,0,-1};
int main(){
int h, w; cin >> h >> w;
vector<vector<int>> a(h,vector<int>(w));
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++){
cin >> a[i][j];
}
auto getxy = [&](int x, int y){
if (x < 0 || x >= h) return numeric_limits<int>::max();
if (y < 0 || y >= w) return numeric_limits<int>::max();
return a[x][y];
};
auto getid = [&](int id){
return a[id/w][id%w];
};
vector<int> ord(h*w); iota(ord.begin(),ord.end(),0);
sort(ord.begin(),ord.end(),[&](int l, int r){
return getid(l) < getid(r);
});
vector<vector<int>> dp(h,vector<int>(w,-1));
int ans = 0;
for (int id : ord){
int x = id/w, y = id%w;
dp[x][y] = 1;
for (int k = 0; k < 4; k++){
int nx = x + dx[k];
int ny = y + dy[k];
if (getxy(nx,ny) < getxy(x,y)){
dp[x][y] = max(dp[x][y], dp[nx][ny]+1);
}
}
ans = max(ans,dp[x][y]);
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0