結果
問題 | No.2639 Longest Increasing Walk |
ユーザー |
![]() |
提出日時 | 2024-02-20 17:50:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,306 bytes |
コンパイル時間 | 444 ms |
コンパイル使用メモリ | 59,196 KB |
実行使用メモリ | 19,644 KB |
最終ジャッジ日時 | 2024-09-29 03:47:21 |
合計ジャッジ時間 | 2,226 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
/* -*- coding: utf-8 -*- * * 2639.cc: No.2639 Longest Increasing Walk - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> using namespace std; /* constant */ const int MAX_H = 500; const int MAX_W = 500; const int MAX_N = MAX_H * MAX_W; /* typedef */ typedef vector<int> vi; typedef queue<int> qi; /* global variables */ int as[MAX_N], pns[MAX_N], ds[MAX_N]; vi nbrs[MAX_N]; /* subroutines */ /* main */ int main() { int h, w; scanf("%d%d", &h, &w); int n = h * w; for (int i = 0; i < n; i++) scanf("%d", as + i); for (int i = 0, u = 0; i < h; i++) for (int j = 0; j < w; j++, u++) { if (i + 1 < h) { int v = u + w; if (as[u] < as[v]) nbrs[u].push_back(v), pns[v]++; else if (as[u] > as[v]) nbrs[v].push_back(u), pns[u]++; } if (j + 1 < w) { int v = u + 1; if (as[u] < as[v]) nbrs[u].push_back(v), pns[v]++; else if (as[u] > as[v]) nbrs[v].push_back(u), pns[u]++; } } qi q; for (int u = 0; u < n; u++) if (pns[u] == 0) q.push(u), ds[u] = 1; int maxd = 0; while (! q.empty()) { int u = q.front(); q.pop(); maxd = max(maxd, ds[u]); for (auto v: nbrs[u]) { ds[v] = max(ds[v], ds[u] + 1); if (--pns[v] == 0) q.push(v); } } printf("%d\n", maxd); return 0; }