結果
問題 |
No.2639 Longest Increasing Walk
|
ユーザー |
![]() |
提出日時 | 2024-02-12 22:31:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 800 bytes |
コンパイル時間 | 2,282 ms |
コンパイル使用メモリ | 203,112 KB |
最終ジャッジ日時 | 2025-02-19 05:48:00 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int h, w; cin >> h >> w; vector a(h, vector<int>(w)); for (int i=0; i<h; i++){ for (int j=0; j<w; j++){ cin >> a[i][j]; } } vector dp(h, vector<int>(w)); vector seen(h, vector<bool>(w)); auto calc = [&](auto self, int i, int j) -> int { if (seen[i][j]) return dp[i][j]; int ret = 1; for (auto [x, y]:{ pair(i+1, j), pair(i-1, j), pair(i, j-1), pair(i, j+1) }){ if (!(0 <= x && x < h)) continue; if (!(0 <= y && y < w)) continue; if (a[i][j] < a[x][y]){ ret = max(ret, self(self, x, y) + 1); } } seen[i][j] = true; dp[i][j] = ret; return ret; }; int ans = 0; for (int i=0; i<h; i++){ for (int j=0; j<w; j++){ ans = max(ans, calc(calc, i, j)); } } cout << ans << '\n'; }