結果

問題 No.2639 Longest Increasing Walk
ユーザー noya2noya2
提出日時 2024-02-12 20:58:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 4,329 ms
コンパイル使用メモリ 255,392 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 20:50:08
合計ジャッジ時間 6,905 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 127 ms
6,676 KB
testcase_05 AC 123 ms
6,676 KB
testcase_06 AC 127 ms
6,676 KB
testcase_07 AC 144 ms
6,676 KB
testcase_08 AC 127 ms
6,676 KB
testcase_09 AC 147 ms
6,676 KB
testcase_10 AC 91 ms
6,676 KB
testcase_11 AC 81 ms
6,676 KB
testcase_12 AC 13 ms
6,676 KB
testcase_13 AC 99 ms
6,676 KB
testcase_14 AC 60 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 47 ms
6,676 KB
testcase_18 AC 68 ms
6,676 KB
testcase_19 AC 18 ms
6,676 KB
testcase_20 AC 40 ms
6,676 KB
testcase_21 AC 81 ms
6,676 KB
testcase_22 AC 29 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 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main(){
    int h, w; cin >> h >> w;
    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];
    }
    auto getxy = [&](int x, int y){
        if (x < 0 || x >= h) return numeric_limits<int>::max();
        if (y < 0 || y >= w) return numeric_limits<int>::max();
        return a[x][y];
    };
    auto getid = [&](int id){
        return a[id/w][id%w];
    };
    vector<int> ord(h*w); iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),[&](int l, int r){
        return getid(l) < getid(r);
    });
    vector<vector<int>> dp(h,vector<int>(w,-1));
    int ans = 0;
    for (int id : ord){
        int x = id/w, y = id%w;
        dp[x][y] = 1;
        for (int k = 0; k < 4; k++){
            int nx = x + dx[k];
            int ny = y + dy[k];
            if (getxy(nx,ny) < getxy(x,y)){
                dp[x][y] = max(dp[x][y], dp[nx][ny]+1);
            }
        }
        ans = max(ans,dp[x][y]);
    }
    cout << ans << endl;
}
0