結果

問題 No.2639 Longest Increasing Walk
ユーザー SSRSSSRS
提出日時 2024-02-19 21:24:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 213,236 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-02-19 21:24:41
合計ジャッジ時間 5,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 114 ms
7,296 KB
testcase_05 AC 107 ms
7,296 KB
testcase_06 AC 109 ms
7,168 KB
testcase_07 AC 120 ms
7,168 KB
testcase_08 AC 109 ms
7,296 KB
testcase_09 AC 120 ms
7,296 KB
testcase_10 AC 77 ms
6,548 KB
testcase_11 AC 70 ms
6,548 KB
testcase_12 AC 13 ms
6,548 KB
testcase_13 AC 85 ms
6,548 KB
testcase_14 AC 47 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 3 ms
6,548 KB
testcase_17 AC 38 ms
6,548 KB
testcase_18 AC 62 ms
6,548 KB
testcase_19 AC 16 ms
6,548 KB
testcase_20 AC 34 ms
6,548 KB
testcase_21 AC 69 ms
6,548 KB
testcase_22 AC 25 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
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<pair<int, int>> P(H * W);
  for (int i = 0; i < H * W; i++){
    P[i] = make_pair(i / W, i % W);
  }
  sort(P.begin(), P.end(), [&](pair<int, int> a, pair<int, int> b){
    return A[a.first][a.second] < A[b.first][b.second];
  });
  vector<vector<int>> dp(H, vector<int>(W, 1));
  int ans = 1;
  for (int i = 0; i < H * W; i++){
    int x = P[i].first;
    int y = P[i].second;
    for (int j = 0; j < 4; j++){
      int x2 = x + dx[j];
      int y2 = y + dy[j];
      if (0 <= x2 && x2 < H && 0 <= y2 && y2 < W){
        if (A[x2][y2] < A[x][y]){
          dp[x][y] = max(dp[x][y], dp[x2][y2] + 1);
          ans = max(ans, dp[x][y]);
        }
      }
    }
  }
  cout << ans << endl;
}
0