結果

問題 No.2157 崖
ユーザー umezoumezo
提出日時 2022-12-09 23:13:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,256 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 205,140 KB
実行使用メモリ 20,176 KB
最終ジャッジ日時 2024-04-22 23:00:38
合計ジャッジ時間 9,065 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,340 KB
testcase_01 AC 6 ms
12,388 KB
testcase_02 AC 5 ms
12,268 KB
testcase_03 AC 5 ms
12,428 KB
testcase_04 AC 5 ms
12,256 KB
testcase_05 AC 5 ms
12,320 KB
testcase_06 AC 6 ms
12,264 KB
testcase_07 AC 6 ms
12,456 KB
testcase_08 WA -
testcase_09 AC 5 ms
12,460 KB
testcase_10 AC 5 ms
12,468 KB
testcase_11 WA -
testcase_12 AC 6 ms
12,444 KB
testcase_13 WA -
testcase_14 AC 516 ms
19,524 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 437 ms
18,468 KB
testcase_18 AC 424 ms
18,336 KB
testcase_19 WA -
testcase_20 AC 564 ms
20,176 KB
testcase_21 AC 562 ms
20,096 KB
testcase_22 AC 409 ms
17,968 KB
testcase_23 AC 5 ms
12,304 KB
testcase_24 AC 6 ms
12,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int dp[1515][1515];
const int INF=1e9+7;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  for(int i=1;i<1515;i++) rep(j,1515) dp[i][j]=INF;
  
  int n,m;
  cin>>n>>m;
  vector<vector<int>> D(n,vector<int> (m));
  rep(i,n) rep(j,m) cin>>D[i][j];
  rep(i,n) sort(ALL(D[i]));
  
  for(int i=1;i<n;i++){
    for(int j=0;j<m;j++){
      auto r=upper_bound(ALL(D[i-1]),D[i][j])-D[i-1].begin();
      if(r==0) continue;
      int ok=r-1,ng=-1;
      while(ok-ng>1){
        int mid=(ok+ng)/2;
        if(dp[i-1][mid]-abs(D[i][j]-D[i-1][mid])>=0) ok=mid;
        else ng=mid;
      }
      if(ok<r-1 && ok>=0) dp[i][j]=min(dp[i][j],max(dp[i-1][ok+1],D[i][j]-D[i-1][ok+1]));
      if(ok>=0) dp[i][j]=min(dp[i][j],max(dp[i-1][ok],D[i][j]-D[i-1][ok]));
      if(ok>0) dp[i][j]=min(dp[i][j],max(dp[i-1][ok-1],D[i][j]-D[i-1][ok-1]));
      dp[i][j]=min(dp[i][j],max(dp[i-1][0],D[i][j]-D[i-1][0]));
      dp[i][j]=min(dp[i][j],max(dp[i-1][r-1],D[i][j]-D[i-1][r-1]));
    }
  }
  int ans=INF;
  rep(j,m) ans=min(ans,dp[n-1][j]);
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}
0