結果

問題 No.2639 Longest Increasing Walk
ユーザー yuyu_5510yuyu_5510
提出日時 2024-02-19 23:05:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,309 bytes
コンパイル時間 1,678 ms
コンパイル使用メモリ 184,544 KB
実行使用メモリ 39,504 KB
最終ジャッジ日時 2024-02-19 23:06:07
合計ジャッジ時間 9,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 147 ms
21,276 KB
testcase_05 AC 882 ms
32,932 KB
testcase_06 AC 680 ms
32,444 KB
testcase_07 AC 1,312 ms
32,224 KB
testcase_08 AC 1,088 ms
32,624 KB
testcase_09 TLE -
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, sc, 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<tuple<int, int, int>, vector<tuple<int, int, int>>> que;
    vector<long long> dist(h*w, 1);
    for(int i = 0;i < h*w;i++){
        que.push(make_tuple(1, -a[i/w][i%w], i));
    }
    while(!que.empty()){
        auto [d, sc, 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_tuple(dist[to], -a[to/w][to%w], to));
            }
        }
    }

    long long ans = 0;
    for(int i = 0;i < h*w;i++){
        ans = max(ans, dist[i]);
    }
    cout << ans << endl;
}
0