結果

問題 No.2639 Longest Increasing Walk
ユーザー ぷらぷら
提出日時 2024-02-19 21:31:07
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 148,260 KB
実行使用メモリ 8,784 KB
最終ジャッジ日時 2024-09-29 01:26:28
合計ジャッジ時間 3,221 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int dp[550][550];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<vector<int>>A(H,vector<int>(W));
    vector<array<int,3>>tmp;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> A[i][j];
            tmp.push_back({A[i][j],i,j});
        }
    }
    sort(tmp.begin(),tmp.end());
    int ans = 0;
    for(int i = 0; i < tmp.size(); i++) {
        int x = tmp[i][1];
        int y = tmp[i][2];
        for(int j = 0; j < 4; j++) {
            int nx = x+dx[j];
            int ny = y+dy[j];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && A[nx][ny] < A[x][y]) {
                dp[x][y] = max(dp[x][y],dp[nx][ny]+1);
            }
        }
        dp[x][y] = max(dp[x][y],1);
        ans = max(ans,dp[x][y]);
    }
    cout << ans << "\n";
}
0