結果

問題 No.2157 崖
ユーザー Suu0313Suu0313
提出日時 2022-12-09 21:49:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5,328 ms / 6,000 ms
コード長 859 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 208,776 KB
実行使用メモリ 11,208 KB
最終ジャッジ日時 2023-08-04 23:21:04
合計ジャッジ時間 40,729 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4,200 ms
8,412 KB
testcase_14 AC 3,325 ms
10,512 KB
testcase_15 AC 4,087 ms
8,432 KB
testcase_16 AC 4,156 ms
8,356 KB
testcase_17 AC 2,794 ms
9,348 KB
testcase_18 AC 2,729 ms
9,340 KB
testcase_19 AC 5,328 ms
9,612 KB
testcase_20 AC 3,614 ms
11,208 KB
testcase_21 AC 3,569 ms
10,888 KB
testcase_22 AC 2,567 ms
8,844 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main() {
  int n, m; cin >> n >> m;

  vector d(n, vector(m, 0));

  for(auto&&v : d){
    for(auto&&e : v) cin >> e;
    sort(begin(v), end(v));
  }

  auto isok = [&](int x) -> bool {
    vector<int> ok(m + 1); iota(begin(ok), end(ok), 0);

    for(int i = 0; i < n - 1; ++i){
      vector<int> nx(m + 1);

      for(int j = 0; j < m; ++j){
        int l = lower_bound(begin(d[i]), end(d[i]), d[i+1][j] - x) - begin(d[i]);
        int r = upper_bound(begin(d[i]), end(d[i]), d[i+1][j]) - begin(d[i]);
        nx[j + 1] = nx[j] + ((ok[r] - ok[l]) > 0);
      }

      ok = nx;
    }
    return ok[m] > 0;
  };

  int inf = 1e9 + 1;
  int ok = inf, ng = -1;
  while(abs(ok-ng) > 1){
    int wj = (ok + ng)/2;
    if(isok(wj)) ok = wj;
    else ng = wj;
  }

  if(ok == inf) ok = -1;
  cout << ok << "\n";

}
0