結果

問題 No.2639 Longest Increasing Walk
ユーザー tobbie
提出日時 2024-05-07 17:25:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 881 bytes
コンパイル時間 1,851 ms
コンパイル使用メモリ 177,816 KB
実行使用メモリ 97,792 KB
最終ジャッジ日時 2024-11-30 12:06:32
合計ジャッジ時間 55,427 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int> (W));
  rep(h, H) rep(w, W)
    cin >> A[h][w];
  vector<int> dh = {0, 1, 0, -1};
  vector<int> dw = {1, 0, -1, 0};
  auto dfs = [&](auto dfs, int x, int y, int l,
		 vector<vector<bool>> f) -> int {
    f[x][y] = true;
    int nl = l;
    rep(i, 4) {
      int nx = x + dh[i];
      int ny = y + dw[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (f[nx][ny]) continue;
      if (A[nx][ny] <= A[x][y]) continue;
      nl = max(dfs(dfs, nx, ny, l+1, f), nl);
    }
    return nl;
  };
  int maxLen = 0;
  rep(h, H) rep(w, W) {
    vector<vector<bool>> f(H, vector<bool> (W, false));
    maxLen = max(dfs(dfs, h, w, 1, f), maxLen);
  }
  cout << maxLen << endl;
  return 0;
}
0