結果

問題 No.2639 Longest Increasing Walk
ユーザー てんぷらてんぷら
提出日時 2024-02-19 21:32:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 4,783 ms
コンパイル使用メモリ 314,060 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2024-02-19 21:32:19
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 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 41 ms
7,368 KB
testcase_05 AC 42 ms
7,368 KB
testcase_06 AC 44 ms
7,224 KB
testcase_07 AC 57 ms
7,216 KB
testcase_08 AC 45 ms
7,232 KB
testcase_09 AC 58 ms
7,236 KB
testcase_10 AC 40 ms
6,676 KB
testcase_11 AC 36 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 44 ms
6,676 KB
testcase_14 AC 24 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 18 ms
6,676 KB
testcase_18 AC 29 ms
6,676 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 19 ms
6,676 KB
testcase_21 AC 36 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 1 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w, 0));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vector<pair<int, int>> ord;
    rep(i, h) rep(j, w) ord.push_back({i, j});
    sort(ord.begin(), ord.end(), [&](pair<int, int> x, pair<int, int> y) {
        return a[x.first][x.second] < a[y.first][y.second];
    });
    vector dp(h, vector<int>(w, 1));
    vector<int> d = {1, 0, -1, 0, 1};
    int ans = 0;
    for(auto [x, y] : ord) {
        rep(i, 4) {
            int nx = x + d[i], ny = y + d[i + 1];
            if(0 <= nx && nx < h && 0 <= ny && ny < w && a[nx][ny] < a[x][y]) {
                dp[x][y] = max(dp[nx][ny] + 1, dp[x][y]);
            }
        }
        ans = max(ans, dp[x][y]);
    }
    cout << ans << endl;
    return 0;
}
0