結果

問題 No.2639 Longest Increasing Walk
ユーザー Today03Today03
提出日時 2024-02-19 22:05:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 217,832 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2024-02-19 22:05:22
合計ジャッジ時間 5,024 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 138 ms
8,500 KB
testcase_05 AC 115 ms
8,500 KB
testcase_06 AC 105 ms
8,484 KB
testcase_07 AC 112 ms
8,476 KB
testcase_08 AC 108 ms
8,492 KB
testcase_09 AC 111 ms
8,496 KB
testcase_10 AC 94 ms
8,072 KB
testcase_11 AC 62 ms
6,676 KB
testcase_12 AC 12 ms
6,676 KB
testcase_13 AC 77 ms
8,112 KB
testcase_14 AC 44 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 44 ms
6,676 KB
testcase_18 AC 51 ms
6,676 KB
testcase_19 AC 17 ms
6,676 KB
testcase_20 AC 31 ms
6,676 KB
testcase_21 AC 62 ms
6,676 KB
testcase_22 AC 23 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using namespace std;
using ll = long long;

const vector<int> dx = {0, 1, 0, -1};
const vector<int> dy = {1, 0, -1, 0};

int main() {
    int H, W;
    cin >> H >> W;
    vector<tuple<int, int, int>> P;
    vector<vector<int>> A(H, vector<int>(W));
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) cin >> A[i][j], P.push_back(make_tuple(A[i][j], i, j));
    sort(P.rbegin(), P.rend());

    int ans = 0;
    vector<vector<int>> dp(H, vector<int>(W, 0));
    for (auto [a, i, j] : P) {
        int res = 0;
        for (int d = 0; d < 4; d++) {
            int ni = i + dx[d], nj = j + dy[d];
            if (0 <= ni && ni < H && 0 <= nj && nj < W && A[ni][nj] > A[i][j]) res = max(res, dp[ni][nj] + 1);
        }
        dp[i][j] = res;
        ans = max(ans, res);
    }

    cout << ++ans << endl;
}
0