結果

問題 No.2639 Longest Increasing Walk
ユーザー twooimp2twooimp2
提出日時 2024-02-20 01:36:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 6,216 ms
コンパイル使用メモリ 312,808 KB
実行使用メモリ 13,196 KB
最終ジャッジ日時 2024-02-20 01:36:48
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 50 ms
13,196 KB
testcase_05 AC 43 ms
13,196 KB
testcase_06 AC 45 ms
13,164 KB
testcase_07 AC 53 ms
13,156 KB
testcase_08 AC 48 ms
13,180 KB
testcase_09 AC 55 ms
13,188 KB
testcase_10 AC 39 ms
12,340 KB
testcase_11 AC 34 ms
8,528 KB
testcase_12 AC 7 ms
6,676 KB
testcase_13 AC 67 ms
12,420 KB
testcase_14 AC 24 ms
8,224 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 27 ms
8,220 KB
testcase_18 AC 28 ms
8,348 KB
testcase_19 AC 8 ms
6,676 KB
testcase_20 AC 17 ms
6,676 KB
testcase_21 AC 33 ms
8,520 KB
testcase_22 AC 13 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using T=tuple<ll,ll,ll>;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main(){
  IO();
  ll h,w;
  cin>>h>>w;
  vector<vector<ll>> a(h,vector<ll>(w));
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  vector<T> v;
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      v.push_back(T(a[i][j],i,j));
    }
  }
  sort(v.begin(),v.end());
  vector<ll> dx={0,0,-1,1};
  vector<ll> dy={-1,1,0,0};
  vector<vector<ll>> dp(h,vector<ll>(w,-1e18));
  for(ll i=0;i<h*w;i++){
    ll x=get<1>(v[i]);
    ll y=get<2>(v[i]);
    dp[x][y]=1;
    for(ll j=0;j<4;j++){
      ll nx=x+dx[j];
      ll ny=y+dy[j];
      if(0<=nx&&nx<h&&0<=ny&&ny<w){
        if(a[nx][ny]<a[x][y]){
          dp[x][y]=max(dp[x][y],dp[nx][ny]+1);
        }
      }
    }
  }
  ll ans=-1e18;
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      ans=max(ans,dp[i][j]);
    }
  }
  cout<<ans<<endl;
}
0