結果

問題 No.2639 Longest Increasing Walk
ユーザー throughthrough
提出日時 2024-02-19 21:52:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 3,452 ms
コンパイル使用メモリ 232,924 KB
実行使用メモリ 39,936 KB
最終ジャッジ日時 2024-02-19 21:52:27
合計ジャッジ時間 5,092 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 31 ms
7,296 KB
testcase_05 AC 30 ms
7,424 KB
testcase_06 AC 53 ms
39,936 KB
testcase_07 AC 34 ms
7,424 KB
testcase_08 AC 31 ms
7,424 KB
testcase_09 AC 32 ms
7,424 KB
testcase_10 AC 21 ms
6,676 KB
testcase_11 AC 21 ms
6,676 KB
testcase_12 AC 5 ms
6,676 KB
testcase_13 AC 23 ms
6,676 KB
testcase_14 AC 14 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 14 ms
6,676 KB
testcase_18 AC 17 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 10 ms
6,676 KB
testcase_21 AC 19 ms
6,676 KB
testcase_22 AC 8 ms
6,676 KB
testcase_23 AC 2 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 1 ms
6,676 KB
testcase_29 AC 1 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;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
#include <atcoder/all>
using namespace atcoder;
// using mint = modint998244353;
// using mint = modint1000000007;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define reps(i, l, r) for(ll i = l; i < r; i++)

// 左上右下の順番
vector<int> dx = {0,-1,0,1};
vector<int> dy = {-1,0,1,0};

inline bool outField(int x,int y,int h,int w){
    if(0 <= x && x < h && 0 <= y && y < w)return false;
    return true;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    ll h, w; cin >> h >> w;
    vector<vector<ll>> a(h,vector<ll>(w)), walk(h,vector<ll>(w,-1));
    rep(i,h) rep(j,w) cin >> a[i][j];
    auto dfs = [&](auto self, ll x, ll y) -> void {
        if( walk[x][y] != -1 ) return;
        ll res = 0;
        rep(d,4) {
            ll nx = x + dx[d], ny = y + dy[d];
            if(outField(nx,ny,h,w)) continue;
            if(a[x][y] < a[nx][ny]) {
                self(self, nx, ny);
                res = max(res, walk[nx][ny]);
            }
        }
        walk[x][y] = res + 1;
        return;
    };
    ll ans = 0;
    rep(i,h) rep(j,w) {
        dfs(dfs, i, j);
        ans = max(ans, walk[i][j]);
    }
    cout << ans << '\n';
    
    return 0;
}
0