結果

問題 No.2639 Longest Increasing Walk
ユーザー KKT89KKT89
提出日時 2024-02-19 21:53:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,534 bytes
コンパイル時間 4,059 ms
コンパイル使用メモリ 225,868 KB
実行使用メモリ 8,524 KB
最終ジャッジ日時 2024-02-19 21:53:38
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 51 ms
8,524 KB
testcase_05 AC 45 ms
8,524 KB
testcase_06 AC 49 ms
8,508 KB
testcase_07 AC 53 ms
8,500 KB
testcase_08 AC 44 ms
8,516 KB
testcase_09 AC 50 ms
8,520 KB
testcase_10 AC 41 ms
8,096 KB
testcase_11 AC 31 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 45 ms
8,136 KB
testcase_14 AC 22 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 24 ms
6,676 KB
testcase_18 AC 28 ms
6,676 KB
testcase_19 AC 7 ms
6,676 KB
testcase_20 AC 16 ms
6,676 KB
testcase_21 AC 33 ms
6,676 KB
testcase_22 AC 13 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    vector<pair<int,pair<int,int>>> v;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
            v.push_back({a[i][j], {i, j}});
        }
    }
    sort(v.begin(), v.end());

    vector<vector<int>> d(h, vector<int>(w, -1));
    for (int i = 0; i < v.size(); ++i) {
        auto [x, y] = v[i].second;
        d[x][y] = 0;
        if (x and a[x-1][y] < a[x][y]) {
            d[x][y] = max(d[x][y], d[x-1][y]+1);
        }
        if (x+1 < h and a[x+1][y] < a[x][y]) {
            d[x][y] = max(d[x][y], d[x+1][y]+1);
        }
        if (y and a[x][y-1] < a[x][y]) {
            d[x][y] = max(d[x][y], d[x][y-1]+1);
        }
        if (y+1 < w and a[x][y+1] < a[x][y]) {
            d[x][y] = max(d[x][y], d[x][y+1]+1);
        }
    }
    int res = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            res = max(res, d[i][j]);
        }
    }
    cout << res+1 << endl;
}
0