結果

問題 No.2639 Longest Increasing Walk
ユーザー ayataka5ayataka5
提出日時 2024-02-19 23:52:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 2,565 ms
コンパイル使用メモリ 210,668 KB
実行使用メモリ 7,344 KB
最終ジャッジ日時 2024-02-19 23:52:25
合計ジャッジ時間 6,025 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 184 ms
7,344 KB
testcase_05 AC 154 ms
7,344 KB
testcase_06 AC 152 ms
7,200 KB
testcase_07 AC 181 ms
7,192 KB
testcase_08 AC 154 ms
7,208 KB
testcase_09 AC 209 ms
7,340 KB
testcase_10 AC 114 ms
6,676 KB
testcase_11 AC 97 ms
6,676 KB
testcase_12 AC 14 ms
6,676 KB
testcase_13 AC 119 ms
6,676 KB
testcase_14 AC 65 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 54 ms
6,676 KB
testcase_18 AC 77 ms
6,676 KB
testcase_19 AC 20 ms
6,676 KB
testcase_20 AC 45 ms
6,676 KB
testcase_21 AC 96 ms
6,676 KB
testcase_22 AC 32 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 3 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 1 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct cell {
    int x, y;
};

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

int main() {
    int H, W;
    cin >> H >> W;
    vector A(H, vector(W, 0));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    auto compare = [&](cell a, cell b) {
        return !(A[a.x][a.y] < A[b.x][b.y]);
    };
    priority_queue<cell, vector<cell>, decltype(compare)> pq{compare};
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) pq.push({i, j});
    vector dp(H, vector(W, 1));
    while(!pq.empty()) {
        cell C = pq.top(); pq.pop();
        for(int dir = 0; dir < 4; dir++) {
            int nx(C.x+dx[dir]), ny(C.y+dy[dir]);
            if(0 <= nx && nx < H && 0 <= ny && ny < W) {
                if(A[C.x][C.y] < A[nx][ny]) dp[nx][ny] = max(dp[C.x][C.y]+1, dp[nx][ny]);
            }
        }
    }
    int ans(0);
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            ans = max(dp[i][j], ans);
        }
    }
    cout << ans << endl;
    return 0;
}
0