結果

問題 No.2639 Longest Increasing Walk
ユーザー t98slidert98slider
提出日時 2024-03-08 03:55:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 207,916 KB
実行使用メモリ 25,216 KB
最終ジャッジ日時 2024-03-08 03:55:54
合計ジャッジ時間 5,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 39 ms
6,548 KB
testcase_05 AC 38 ms
6,548 KB
testcase_06 AC 38 ms
6,548 KB
testcase_07 AC 54 ms
25,216 KB
testcase_08 AC 39 ms
6,548 KB
testcase_09 AC 39 ms
6,548 KB
testcase_10 AC 25 ms
6,548 KB
testcase_11 AC 23 ms
6,548 KB
testcase_12 AC 5 ms
6,548 KB
testcase_13 AC 27 ms
6,548 KB
testcase_14 AC 17 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 16 ms
6,548 KB
testcase_18 AC 19 ms
6,548 KB
testcase_19 AC 6 ms
6,548 KB
testcase_20 AC 12 ms
6,548 KB
testcase_21 AC 22 ms
6,548 KB
testcase_22 AC 9 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 1 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 1 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0