結果

問題 No.2639 Longest Increasing Walk
ユーザー yuyu_5510yuyu_5510
提出日時 2024-02-19 23:03:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,261 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 181,088 KB
実行使用メモリ 34,252 KB
最終ジャッジ日時 2024-02-19 23:03:17
合計ジャッジ時間 6,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 135 ms
20,252 KB
testcase_05 AC 681 ms
31,908 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();
      |              ^

ソースコード

diff #

#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();
        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;
}
0