結果

問題 No.2639 Longest Increasing Walk
ユーザー through
提出日時 2024-02-19 21:52:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,320 bytes
コンパイル時間 3,405 ms
コンパイル使用メモリ 232,964 KB
実行使用メモリ 39,808 KB
最終ジャッジ日時 2024-09-29 01:50:56
合計ジャッジ時間 4,901 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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