結果

問題 No.2639 Longest Increasing Walk
ユーザー tobbietobbie
提出日時 2024-05-07 21:34:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 181,000 KB
実行使用メモリ 32,768 KB
最終ジャッジ日時 2024-05-07 21:34:25
合計ジャッジ時間 5,571 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 114 ms
6,988 KB
testcase_05 AC 187 ms
32,768 KB
testcase_06 AC 196 ms
32,256 KB
testcase_07 AC 243 ms
32,256 KB
testcase_08 AC 204 ms
32,512 KB
testcase_09 AC 256 ms
32,640 KB
testcase_10 AC 198 ms
20,096 KB
testcase_11 AC 162 ms
18,304 KB
testcase_12 AC 19 ms
6,016 KB
testcase_13 AC 204 ms
21,248 KB
testcase_14 AC 100 ms
13,824 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 163 ms
15,616 KB
testcase_19 AC 27 ms
6,656 KB
testcase_20 AC 71 ms
10,880 KB
testcase_21 AC 173 ms
18,176 KB
testcase_22 AC 47 ms
8,832 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct Grid {
  int h;
  int w;
  Grid (int h, int w) : h(h), w(w) {}
};

struct Walk {
  int val;
  int length;
  Walk (int val, int length) : val(val), length(length) {}
};

int main() {
  int H, W;
  cin >> H >> W;
  map<int, vector<Grid>> g;
  rep(h, H) rep(w, W) {
    int val;
    cin >> val;
    g[val].push_back(Grid(h, w));
  }
  vector<int> dh = {0, 1, 0, -1};
  vector<int> dw = {1, 0, -1, 0};
  vector<vector<Walk>> dp(H, vector<Walk> (W, Walk(0, 0)));
  int length = 1;
  for (auto it = g.begin(); it != g.end(); it++) {
    int val = it->first;
    for (Grid p : it->second) {
      int len = -1;
      rep(i, 4) {
	int nh = p.h + dh[i];
	int nw = p.w + dw[i];
	if (nh < 0 || nh > H-1 || nw < 0 || nw > W-1) continue;
	if (dp[nh][nw].val < val)
	  len = max(dp[nh][nw].length, len);
      }
      if (len >= 0) {
	dp[p.h][p.w] = {val, len + 1};
	length = max(len + 1, length);
      }
    }
  }
  cout << length << endl;
  return 0;
}
0