結果

問題 No.2639 Longest Increasing Walk
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-29 10:00:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 215,848 KB
実行使用メモリ 8,396 KB
最終ジャッジ日時 2024-02-29 10:00:52
合計ジャッジ時間 6,432 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 51 ms
8,396 KB
testcase_05 AC 48 ms
8,396 KB
testcase_06 AC 51 ms
8,380 KB
testcase_07 AC 102 ms
8,372 KB
testcase_08 AC 58 ms
8,388 KB
testcase_09 AC 63 ms
8,392 KB
testcase_10 AC 42 ms
7,968 KB
testcase_11 AC 38 ms
6,676 KB
testcase_12 AC 7 ms
6,676 KB
testcase_13 AC 45 ms
8,008 KB
testcase_14 AC 27 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 29 ms
6,676 KB
testcase_18 AC 40 ms
6,676 KB
testcase_19 AC 10 ms
6,676 KB
testcase_20 AC 19 ms
6,676 KB
testcase_21 AC 38 ms
6,676 KB
testcase_22 AC 16 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 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int H, W, x, h, w;
    cin >> H >> W;
    vector<tuple<int, int, int>> v;
    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];
            v.push_back(make_tuple(a[i][j], i, j));
        }
    }

    sort(v.begin(), v.end());

    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};

    vector ans(H, vector<int>(W, 0));

    for (auto [z, h, w] : v){
        for (int i=0; i<4; i++){
            int nh = h + dx[i];
            int nw = w + dy[i];
            if (0 <= nh && nh < H && 0 <= nw && nw < W){
                if (a[nh][nw] > a[h][w]) ans[nh][nw] = max(ans[nh][nw], ans[h][w] + 1);
            }
        }
    }

    int res = 0;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            res = max(res, ans[i][j]);
        }
    }

    cout << res + 1 << endl;

    return 0;
}
0