結果
問題 | No.2639 Longest Increasing Walk |
ユーザー | srjywrdnprkt |
提出日時 | 2024-02-29 10:00:45 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,043 bytes |
コンパイル時間 | 2,197 ms |
コンパイル使用メモリ | 215,984 KB |
実行使用メモリ | 8,144 KB |
最終ジャッジ日時 | 2024-09-29 12:38:37 |
合計ジャッジ時間 | 4,172 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int H, W, x, h, w; cin >> H >> W; vector<tuple<int, int, int>> v; 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]; v.push_back(make_tuple(a[i][j], i, j)); } } sort(v.begin(), v.end()); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; vector ans(H, vector<int>(W, 0)); for (auto [z, h, w] : v){ for (int i=0; i<4; i++){ int nh = h + dx[i]; int nw = w + dy[i]; if (0 <= nh && nh < H && 0 <= nw && nw < W){ if (a[nh][nw] > a[h][w]) ans[nh][nw] = max(ans[nh][nw], ans[h][w] + 1); } } } int res = 0; for (int i=0; i<H; i++){ for (int j=0; j<W; j++){ res = max(res, ans[i][j]); } } cout << res + 1 << endl; return 0; }