結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
nono00
|
| 提出日時 | 2024-02-19 22:42:06 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 1,443 bytes |
| コンパイル時間 | 2,944 ms |
| コンパイル使用メモリ | 254,536 KB |
| 実行使用メモリ | 18,928 KB |
| 最終ジャッジ日時 | 2024-09-29 02:33:03 |
| 合計ジャッジ時間 | 4,710 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
void solve() {
int h, w;
std::cin >> h >> w;
auto encode = [&](int i, int j) {
return i * w + j;
};
std::vector a(h, std::vector<int>(w));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
std::cin >> a[i][j];
}
}
std::vector graph(h * w, std::vector<int>());
const int DI[] = {1, 0, -1, 0};
const int DJ[] = {0, 1, 0, -1};
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int k = encode(i, j);
for (int d = 0; d < 4; d++) {
int ni = i + DI[d];
int nj = j + DJ[d];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
if (a[i][j] >= a[ni][nj]) continue;
int nk = encode(ni, nj);
graph[k].push_back(nk);
}
}
}
std::vector<int> dp(h * w, -1);
auto dfs = [&](auto self, int u) -> int {
if (dp[u] != -1) return dp[u];
dp[u] = 1;
for (int v: graph[u]) {
dp[u] = std::max(dp[u], self(self, v) + 1);
}
return dp[u];
};
int ans = 0;
for (int i = 0; i < h * w; i++) {
ans = std::max(ans, dfs(dfs, i));
}
std::cout << ans << '\n';
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
std::cout << std::fixed << std::setprecision(16);
int t = 1;
while (t--) solve();
}
nono00