結果
| 問題 | 
                            No.2639 Longest Increasing Walk
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yuyu_5510
                         | 
                    
| 提出日時 | 2024-02-19 23:00:38 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,279 bytes | 
| コンパイル時間 | 1,879 ms | 
| コンパイル使用メモリ | 181,980 KB | 
| 実行使用メモリ | 34,756 KB | 
| 最終ジャッジ日時 | 2024-09-29 02:43:06 | 
| 合計ジャッジ時間 | 5,756 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 TLE * 1 -- * 27 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   37 |         auto [d, v] = que.top(); que.pop();
      |              ^
            
            ソースコード
#include<bits/stdc++.h>
using namespace std;
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];
    }
   }
   vector<vector<int>> g(h*w);
   vector<vector<int>> gr(h*w);
   int dx[] = {1, 0, -1, 0};
   int dy[] = {0, 1, 0, -1};
   for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
        for(int k = 0;k < 4;k++){
            int nx = i + dx[k], ny = j + dy[k];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if(a[i][j] < a[nx][ny]){
                g[i*w+j].push_back(nx*w+ny);
            }
        }
    }
   }
    priority_queue<pair<int, int>, vector<pair<int, int>>> que;
    vector<long long> dist(h*w, 1);
    for(int i = 0;i < h*w;i++){
        que.push(make_pair(1, -i));
    }
    while(!que.empty()){
        auto [d, v] = que.top(); que.pop();
        v = -v;
        if(dist[v] > d) continue;
        for(auto to: g[v]){
            if(dist[to] < dist[v] + 1){
                dist[to] = dist[v] + 1;
                que.push(make_pair(dist[to], -to));
            }
        }
    }
    long long ans = 0;
    for(int i = 0;i < h*w;i++){
        ans = max(ans, dist[i]);
    }
    cout << ans << endl;
}
            
            
            
        
            
yuyu_5510