結果

問題 No.2639 Longest Increasing Walk
ユーザー yansi819yansi819
提出日時 2024-04-04 08:55:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,082 bytes
コンパイル時間 4,611 ms
コンパイル使用メモリ 266,224 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-04 08:55:57
合計ジャッジ時間 9,198 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 137 ms
6,676 KB
testcase_05 AC 134 ms
6,676 KB
testcase_06 AC 139 ms
6,676 KB
testcase_07 AC 162 ms
6,676 KB
testcase_08 AC 144 ms
6,676 KB
testcase_09 AC 171 ms
6,676 KB
testcase_10 AC 103 ms
6,676 KB
testcase_11 AC 92 ms
6,676 KB
testcase_12 AC 15 ms
6,676 KB
testcase_13 AC 111 ms
6,676 KB
testcase_14 AC 63 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 50 ms
6,676 KB
testcase_18 AC 75 ms
6,676 KB
testcase_19 AC 21 ms
6,676 KB
testcase_20 AC 45 ms
6,676 KB
testcase_21 AC 91 ms
6,676 KB
testcase_22 AC 32 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 #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

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<int> ord(h * w);
  for (int i = 0; i < h * w; i++) ord[i] = i;
  sort(ord.begin(), ord.end(), [&](int l, int r) {
    return a[l / w][l % w] < a[r / w][r % w];
  });
  vector<vector<int>> dp(h, vector<int>(w));
  for (int i = 0; i < h * w; i++) {
    int x = ord[i] / w;
    int y = ord[i] % w;
    dp[x][y] = 1;
    for (int j = 0; j < 4; j++) {
      int nx = x + dx[j];
      int ny = y + dy[j];
      if (0 > nx || nx >= h || 0 > ny || ny >= w) continue;
      if (a[nx][ny] < a[x][y]) {
        dp[x][y] = max(dp[x][y], dp[nx][ny] + 1);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) ans = max(ans, dp[i / w][i % w]);
  cout << ans << endl;
  return 0;
}
0