結果
問題 | No.2639 Longest Increasing Walk |
ユーザー |
|
提出日時 | 2024-03-08 03:55:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 956 bytes |
コンパイル時間 | 2,219 ms |
コンパイル使用メモリ | 200,532 KB |
最終ジャッジ日時 | 2025-02-20 01:48:29 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ios::sync_with_stdio(false);cin.tie(0);int h, w;cin >> h >> w;vector<vector<int>> dp(h, vector<int>(w, -1)), A(h, vector<int>(w));auto rec = [&](auto rec, int y, int x) -> int {if(dp[y][x] != -1) return dp[y][x];dp[y][x] = 1;for(int i = 0; i < 4; i++){int ny = y + (i == 0) - (i == 1);int nx = x + (i == 2) - (i == 3);if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;if(A[y][x] < A[ny][nx]) dp[y][x] = max(dp[y][x], rec(rec, ny, nx) + 1);}return dp[y][x];};for(int y = 0; y < h; y++){for(int x = 0; x < w; x++){cin >> A[y][x];}}int ans = 0;for(int y = 0; y < h; y++){for(int x = 0; x < w; x++){ans = max(ans, rec(rec, y, x));}}cout << ans << '\n';}