結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 21:53:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 1,534 bytes |
| コンパイル時間 | 3,516 ms |
| コンパイル使用メモリ | 223,884 KB |
| 最終ジャッジ日時 | 2025-02-19 16:55:06 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h,w; cin >> h >> w;
vector<vector<int>> a(h, vector<int>(w));
vector<pair<int,pair<int,int>>> v;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> a[i][j];
v.push_back({a[i][j], {i, j}});
}
}
sort(v.begin(), v.end());
vector<vector<int>> d(h, vector<int>(w, -1));
for (int i = 0; i < v.size(); ++i) {
auto [x, y] = v[i].second;
d[x][y] = 0;
if (x and a[x-1][y] < a[x][y]) {
d[x][y] = max(d[x][y], d[x-1][y]+1);
}
if (x+1 < h and a[x+1][y] < a[x][y]) {
d[x][y] = max(d[x][y], d[x+1][y]+1);
}
if (y and a[x][y-1] < a[x][y]) {
d[x][y] = max(d[x][y], d[x][y-1]+1);
}
if (y+1 < w and a[x][y+1] < a[x][y]) {
d[x][y] = max(d[x][y], d[x][y+1]+1);
}
}
int res = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
res = max(res, d[i][j]);
}
}
cout << res+1 << endl;
}