結果

問題 No.2639 Longest Increasing Walk
ユーザー GOTKAKOGOTKAKO
提出日時 2024-02-19 21:44:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 938 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 218,412 KB
実行使用メモリ 8,396 KB
最終ジャッジ日時 2024-02-19 21:44:07
合計ジャッジ時間 4,175 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 1 ms
6,676 KB
testcase_04 AC 44 ms
8,396 KB
testcase_05 AC 45 ms
8,396 KB
testcase_06 AC 45 ms
8,380 KB
testcase_07 AC 52 ms
8,372 KB
testcase_08 AC 48 ms
8,388 KB
testcase_09 AC 53 ms
8,392 KB
testcase_10 AC 36 ms
7,968 KB
testcase_11 AC 32 ms
6,676 KB
testcase_12 AC 7 ms
6,676 KB
testcase_13 AC 39 ms
8,008 KB
testcase_14 AC 23 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 30 ms
6,676 KB
testcase_18 AC 26 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 17 ms
6,676 KB
testcase_21 AC 32 ms
6,676 KB
testcase_22 AC 12 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 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 1 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() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,W; cin >> H >> W;
    vector<tuple<int,int,int>> X;
    vector<vector<int>> A(H,vector<int>(W));
    for(int i=0; i<H; i++) for(int k=0; k<W; k++){
        int a; cin >> a;
        A.at(i).at(k) = a;
        X.push_back({a,i,k});
    }
    sort(X.rbegin(),X.rend());

    vector dist(H,vector<int>(W));
    vector<int> dx = {-1,0,1,0},dy = {0,1,0,-1};
    for(auto [a,x,y] : X){
        int now = dist.at(x).at(y);
        for(int i=0; i<4; i++){
            int nx = x+dx.at(i),ny = y+dy.at(i);
            if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if(A.at(nx).at(ny) >= a) continue;
            dist.at(nx).at(ny) = max(dist.at(nx).at(ny),now+1);
        }
    }


    int answer = 0;
    for(auto &h : dist) for(auto &w : h) answer = max(answer,w);
    cout << answer+1 << endl; 
}
0