結果
| 問題 | No.2639 Longest Increasing Walk |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-10 15:51:48 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 75 ms / 2,000 ms |
| コード長 | 1,155 bytes |
| コンパイル時間 | 3,590 ms |
| コンパイル使用メモリ | 279,728 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-10 15:51:55 |
| 合計ジャッジ時間 | 6,155 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int h, w;
int a[maxn][maxn];
int dp[maxn][maxn];
bool isin(int i, int j) { return 0 <= i && i < h && 0 <= j && j < w; }
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> h >> w;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
priority_queue<pair<int, int>> pq;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
pq.push({a[i][j], i * w + j});
}
}
const int dx[] = {1, 0, -1, 0, 1};
while (pq.size()) {
auto [v, idx] = pq.top();
pq.pop();
int i = idx / w, j = idx % w;
int mx = 0;
for (int r = 0; r < 4; r++) {
int ni = i + dx[r], nj = j + dx[r + 1];
if (!isin(ni, nj)) continue;
if (v < a[ni][nj]) {
mx = max(mx, dp[ni][nj]);
}
}
dp[i][j] = mx + 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";
}