結果
問題 | No.2639 Longest Increasing Walk |
ユーザー | zawakasu |
提出日時 | 2024-02-19 21:43:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,931 bytes |
コンパイル時間 | 2,187 ms |
コンパイル使用メモリ | 208,820 KB |
実行使用メモリ | 21,080 KB |
最終ジャッジ日時 | 2024-02-19 21:43:13 |
合計ジャッジ時間 | 4,281 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge16 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,676 KB |
testcase_01 | AC | 2 ms
6,676 KB |
testcase_02 | AC | 2 ms
6,676 KB |
testcase_03 | AC | 1 ms
6,676 KB |
testcase_04 | AC | 44 ms
13,268 KB |
testcase_05 | AC | 72 ms
21,080 KB |
testcase_06 | AC | 70 ms
20,812 KB |
testcase_07 | AC | 88 ms
20,744 KB |
testcase_08 | AC | 70 ms
20,944 KB |
testcase_09 | AC | 85 ms
21,000 KB |
testcase_10 | AC | 47 ms
12,964 KB |
testcase_11 | AC | 42 ms
11,576 KB |
testcase_12 | AC | 8 ms
6,676 KB |
testcase_13 | AC | 49 ms
13,600 KB |
testcase_14 | AC | 29 ms
9,216 KB |
testcase_15 | AC | 2 ms
6,676 KB |
testcase_16 | AC | 3 ms
6,676 KB |
testcase_17 | AC | 28 ms
9,088 KB |
testcase_18 | AC | 35 ms
10,200 KB |
testcase_19 | AC | 11 ms
6,676 KB |
testcase_20 | AC | 22 ms
7,552 KB |
testcase_21 | AC | 42 ms
11,524 KB |
testcase_22 | AC | 16 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 | 2 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 | 1 ms
6,676 KB |
ソースコード
#include <bits/stdc++.h> namespace zawa { using i16 = std::int16_t; using i32 = std::int32_t; using i64 = std::int64_t; using i128 = __int128_t; using u8 = std::uint8_t; using u16 = std::uint16_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using usize = std::size_t; } // namespace zawa namespace zawa { void SetFastIO() { std::cin.tie(nullptr)->sync_with_stdio(false); } void SetPrecision(u32 dig) { std::cout << std::fixed << std::setprecision(dig); } } // namespace zawa using namespace zawa; int dx[4]{ 0, 1, 0, -1 }; int dy[4]{ 1, 0, -1, 0 }; int main() { SetFastIO(); int h, w; std::cin >> h >> w; std::vector a(h, std::vector<int>(w)); for (int i{} ; i < h ; i++) for (int j{} ; j < w ; j++) std::cin >> a[i][j]; int n{h * w}; auto f{[&](int x, int y) -> int { return x * w + y; }}; auto in{[&](int x, int y) -> bool { return 0 <= x and x < h and 0 <= y and y < w; }}; std::vector g(n, std::vector<int>{}); std::vector<int> deg(n); for (int x{} ; x < h ; x++) { for (int y{} ; y < w ; y++) { for (int d{} ; d < 4 ; d++) { int nx{x + dx[d]}, ny{y + dy[d]}; if (!in(nx, ny)) continue; if (a[x][y] < a[nx][ny]) { g[f(x, y)].push_back(f(nx, ny)); deg[f(nx, ny)]++; } } } } std::vector<int> que; std::vector<int> dp(n); for (int i{} ; i < n ; i++) if (deg[i] == 0) { que.push_back(i); dp[i] = 1; } for (int i{} ; i < (int)que.size() ; i++) { int v{que[i]}; for (auto x : g[v]) { dp[x] = std::max(dp[x], dp[v] + 1); deg[x]--; if (deg[x] == 0) { que.push_back(x); } } } int ans{*std::max_element(dp.begin(), dp.end())}; std::cout << ans << '\n'; }