結果
| 問題 |
No.2639 Longest Increasing Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-02-19 23:52:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 199 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| コンパイル時間 | 2,310 ms |
| コンパイル使用メモリ | 200,576 KB |
| 最終ジャッジ日時 | 2025-02-19 17:48:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct cell {
int x, y;
};
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int main() {
int H, W;
cin >> H >> W;
vector A(H, vector(W, 0));
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
cin >> A[i][j];
}
}
auto compare = [&](cell a, cell b) {
return !(A[a.x][a.y] < A[b.x][b.y]);
};
priority_queue<cell, vector<cell>, decltype(compare)> pq{compare};
for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) pq.push({i, j});
vector dp(H, vector(W, 1));
while(!pq.empty()) {
cell C = pq.top(); pq.pop();
for(int dir = 0; dir < 4; dir++) {
int nx(C.x+dx[dir]), ny(C.y+dy[dir]);
if(0 <= nx && nx < H && 0 <= ny && ny < W) {
if(A[C.x][C.y] < A[nx][ny]) dp[nx][ny] = max(dp[C.x][C.y]+1, dp[nx][ny]);
}
}
}
int ans(0);
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
ans = max(dp[i][j], ans);
}
}
cout << ans << endl;
return 0;
}