結果
| 問題 | 
                            No.2639 Longest Increasing Walk
                             | 
                    
| コンテスト | |
| ユーザー | 
                             srjywrdnprkt
                         | 
                    
| 提出日時 | 2024-02-29 10:00:45 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 61 ms / 2,000 ms | 
| コード長 | 1,043 bytes | 
| コンパイル時間 | 2,293 ms | 
| コンパイル使用メモリ | 208,624 KB | 
| 最終ジャッジ日時 | 2025-02-19 21:57:01 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 33 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int H, W, x, h, w;
    cin >> H >> W;
    vector<tuple<int, int, int>> v;
    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];
            v.push_back(make_tuple(a[i][j], i, j));
        }
    }
    sort(v.begin(), v.end());
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    vector ans(H, vector<int>(W, 0));
    for (auto [z, h, w] : v){
        for (int i=0; i<4; i++){
            int nh = h + dx[i];
            int nw = w + dy[i];
            if (0 <= nh && nh < H && 0 <= nw && nw < W){
                if (a[nh][nw] > a[h][w]) ans[nh][nw] = max(ans[nh][nw], ans[h][w] + 1);
            }
        }
    }
    int res = 0;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            res = max(res, ans[i][j]);
        }
    }
    cout << res + 1 << endl;
    return 0;
}
            
            
            
        
            
srjywrdnprkt