結果

問題 No.2639 Longest Increasing Walk
ユーザー inkyamaninkyaman
提出日時 2024-03-24 10:32:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 116,636 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-24 10:33:02
合計ジャッジ時間 4,766 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 115 ms
6,676 KB
testcase_05 AC 109 ms
6,676 KB
testcase_06 AC 107 ms
6,676 KB
testcase_07 AC 106 ms
6,676 KB
testcase_08 AC 107 ms
6,676 KB
testcase_09 AC 108 ms
6,676 KB
testcase_10 AC 64 ms
6,676 KB
testcase_11 AC 57 ms
6,676 KB
testcase_12 AC 11 ms
6,676 KB
testcase_13 AC 76 ms
6,676 KB
testcase_14 AC 41 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 39 ms
6,676 KB
testcase_18 AC 48 ms
6,676 KB
testcase_19 AC 14 ms
6,676 KB
testcase_20 AC 30 ms
6,676 KB
testcase_21 AC 58 ms
6,676 KB
testcase_22 AC 22 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
#include <tuple>
using namespace std;
using ll = long long;

int H, W;
int A[505][505], vis[505][505];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

void dfs(int y, int x) {

    int mx = 0;
    for(int i = 0; i < 4; ++i) {
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
        if(A[y][x] >= A[ny][nx]) continue;
        if(vis[ny][nx] == 0) dfs(ny, nx);
        mx = max(mx, vis[ny][nx]);
    }

    vis[y][x] = mx+1;

}

int main() {

    cin >> H >> W;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            cin >> A[i][j];
        }
    } 

    int ans = 0;
    for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
            if(vis[i][j] != 0) {
                ans = max(ans, vis[i][j]);
                continue;
            }
            dfs(i,j);
            ans = max(ans,vis[i][j]);
        }
    }

    cout << ans << endl;

}
0