結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-09 21:49:29 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5,757 ms / 6,000 ms |
| コード長 | 859 bytes |
| コンパイル時間 | 2,210 ms |
| コンパイル使用メモリ | 203,660 KB |
| 最終ジャッジ日時 | 2025-02-09 07:51:44 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#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";
}