結果

問題 No.2157 崖
ユーザー umezoumezo
提出日時 2022-12-09 23:02:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 2,837 ms
コンパイル使用メモリ 202,832 KB
実行使用メモリ 20,368 KB
最終ジャッジ日時 2024-04-22 22:55:15
合計ジャッジ時間 9,054 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,384 KB
testcase_01 AC 5 ms
12,440 KB
testcase_02 AC 6 ms
12,416 KB
testcase_03 AC 6 ms
12,440 KB
testcase_04 AC 5 ms
12,312 KB
testcase_05 AC 6 ms
12,272 KB
testcase_06 AC 6 ms
12,312 KB
testcase_07 AC 5 ms
12,316 KB
testcase_08 WA -
testcase_09 AC 6 ms
12,516 KB
testcase_10 AC 6 ms
12,440 KB
testcase_11 WA -
testcase_12 AC 6 ms
12,440 KB
testcase_13 WA -
testcase_14 AC 491 ms
19,432 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 413 ms
18,568 KB
testcase_18 AC 402 ms
18,292 KB
testcase_19 WA -
testcase_20 AC 538 ms
20,368 KB
testcase_21 AC 540 ms
20,080 KB
testcase_22 AC 387 ms
18,072 KB
testcase_23 AC 6 ms
12,568 KB
testcase_24 AC 6 ms
12,500 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]));
    }
  }
  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