結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2024-02-19 21:24:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 988 bytes |
| コンパイル時間 | 2,772 ms |
| コンパイル使用メモリ | 204,380 KB |
| 最終ジャッジ日時 | 2025-02-19 16:33:46 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> 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];
}
}
vector<pair<int, int>> P(H * W);
for (int i = 0; i < H * W; i++){
P[i] = make_pair(i / W, i % W);
}
sort(P.begin(), P.end(), [&](pair<int, int> a, pair<int, int> b){
return A[a.first][a.second] < A[b.first][b.second];
});
vector<vector<int>> dp(H, vector<int>(W, 1));
int ans = 1;
for (int i = 0; i < H * W; i++){
int x = P[i].first;
int y = P[i].second;
for (int j = 0; j < 4; j++){
int x2 = x + dx[j];
int y2 = y + dy[j];
if (0 <= x2 && x2 < H && 0 <= y2 && y2 < W){
if (A[x2][y2] < A[x][y]){
dp[x][y] = max(dp[x][y], dp[x2][y2] + 1);
ans = max(ans, dp[x][y]);
}
}
}
}
cout << ans << endl;
}
SSRS