結果
問題 | No.2639 Longest Increasing Walk |
ユーザー | shobonvip |
提出日時 | 2024-02-12 22:31:12 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 800 bytes |
コンパイル時間 | 2,425 ms |
コンパイル使用メモリ | 211,084 KB |
実行使用メモリ | 45,312 KB |
最終ジャッジ日時 | 2024-09-29 01:11:39 |
合計ジャッジ時間 | 5,648 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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'; }