結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,400 KB
testcase_01 AC 5 ms
12,496 KB
testcase_02 AC 6 ms
12,536 KB
testcase_03 AC 6 ms
12,392 KB
testcase_04 AC 6 ms
12,508 KB
testcase_05 AC 5 ms
12,424 KB
testcase_06 AC 6 ms
12,376 KB
testcase_07 AC 6 ms
12,320 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
12,420 KB
testcase_11 WA -
testcase_12 AC 6 ms
12,428 KB
testcase_13 WA -
testcase_14 AC 488 ms
19,424 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 416 ms
18,456 KB
testcase_18 AC 406 ms
18,360 KB
testcase_19 WA -
testcase_20 AC 539 ms
20,388 KB
testcase_21 AC 534 ms
20,236 KB
testcase_22 AC 389 ms
18,048 KB
testcase_23 AC 6 ms
12,448 KB
testcase_24 AC 5 ms
12,440 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>0) dp[i][j]=min(max(dp[i-1][ok],D[i][j]-D[i-1][ok]),max(dp[i-1][ok-1],D[i][j]-D[i-1][ok-1]));
      else if(ok==0) dp[i][j]=max(dp[i-1][ok],D[i][j]-D[i-1][ok]);
      else continue;
    }
  }
  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