結果

問題 No.2157 崖
ユーザー Suu0313Suu0313
提出日時 2022-12-09 21:49:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5,058 ms / 6,000 ms
コード長 859 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 205,968 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-22 21:44:32
合計ジャッジ時間 41,124 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 4,113 ms
8,576 KB
testcase_14 AC 3,515 ms
10,624 KB
testcase_15 AC 4,031 ms
8,320 KB
testcase_16 AC 4,076 ms
8,448 KB
testcase_17 AC 2,920 ms
9,472 KB
testcase_18 AC 2,908 ms
9,472 KB
testcase_19 AC 5,058 ms
9,856 KB
testcase_20 AC 3,736 ms
11,520 KB
testcase_21 AC 3,762 ms
11,392 KB
testcase_22 AC 2,782 ms
9,088 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 4 ms
6,944 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