結果

問題 No.2639 Longest Increasing Walk
ユーザー otoshigootoshigo
提出日時 2024-02-19 21:49:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 998 ms
コンパイル使用メモリ 91,340 KB
実行使用メモリ 8,396 KB
最終ジャッジ日時 2024-02-19 21:49:06
合計ジャッジ時間 3,081 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 51 ms
8,396 KB
testcase_05 AC 46 ms
8,396 KB
testcase_06 AC 47 ms
8,380 KB
testcase_07 AC 57 ms
8,372 KB
testcase_08 AC 51 ms
8,388 KB
testcase_09 AC 58 ms
8,392 KB
testcase_10 AC 41 ms
7,968 KB
testcase_11 AC 36 ms
6,548 KB
testcase_12 AC 7 ms
6,548 KB
testcase_13 AC 44 ms
8,008 KB
testcase_14 AC 25 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 3 ms
6,548 KB
testcase_17 AC 29 ms
6,548 KB
testcase_18 AC 30 ms
6,548 KB
testcase_19 AC 9 ms
6,548 KB
testcase_20 AC 19 ms
6,548 KB
testcase_21 AC 36 ms
6,548 KB
testcase_22 AC 14 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 1 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin>>H>>W;
    vector A(H,vector<int>(W));
    vector<tuple<int,int,int>>V;
    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));
    }
    vector D(H,vector<int>(W));
    sort(all(V));
    for(auto[a,x,y]:V){
        for(int i=0;i<4;i++){
            int ex=x+dx[i],ey=y+dy[i];
            if(ex>=0&&ex<H&&ey>=0&&ey<W&&A[x][y]<A[ex][ey]){
                chmax(D[ex][ey],D[x][y]+1);
            }
        }
    }
    int ans=0;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)chmax(ans,D[i][j]);
    ans++;
    cout<<ans<<"\n";
}
0