結果

問題 No.2639 Longest Increasing Walk
ユーザー ripityripity
提出日時 2024-02-19 21:55:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 3,398 ms
コンパイル使用メモリ 215,884 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2024-02-19 21:55:50
合計ジャッジ時間 5,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 118 ms
8,500 KB
testcase_05 AC 112 ms
8,500 KB
testcase_06 AC 107 ms
8,484 KB
testcase_07 AC 126 ms
8,476 KB
testcase_08 AC 109 ms
8,492 KB
testcase_09 AC 118 ms
8,496 KB
testcase_10 AC 73 ms
8,072 KB
testcase_11 AC 65 ms
6,676 KB
testcase_12 AC 11 ms
6,676 KB
testcase_13 AC 77 ms
8,112 KB
testcase_14 AC 49 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 49 ms
6,676 KB
testcase_18 AC 54 ms
6,676 KB
testcase_19 AC 16 ms
6,676 KB
testcase_20 AC 36 ms
6,676 KB
testcase_21 AC 68 ms
6,676 KB
testcase_22 AC 25 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;

int main() {
    int H, W;
    cin >> H >> W;
    vector A(H, vector<int>(W));
    vector<tuple<int, int, int>> cell;
    for( int i = 0; i < H; i++ ) {
        for( int j = 0; j < W; j++ ) {
            cin >> A[i][j];
            cell.push_back(make_tuple(A[i][j], i, j));
        }
    }
    int ans = 0;
    constexpr int INF = 1<<30;
    vector dp(H, vector<int>(W, 1));
    sort(cell.begin(), cell.end());
    for( auto [a, i, j] : cell ) {
        ans = max(ans, dp[i][j]);
        if( i-1 >= 0 && A[i-1][j] > a ) dp[i-1][j] = max(dp[i-1][j], dp[i][j]+1);
        if( i+1 <= H-1 && A[i+1][j] > a ) dp[i+1][j] = max(dp[i+1][j], dp[i][j]+1);
        if( j-1 >= 0 && A[i][j-1] > a ) dp[i][j-1] = max(dp[i][j-1], dp[i][j]+1);
        if( j+1 <= W-1 && A[i][j+1] > a ) dp[i][j+1] = max(dp[i][j+1], dp[i][j]+1);
    }
    cout << ans << endl;
}
0