結果
問題 |
No.2157 崖
|
ユーザー |
|
提出日時 | 2025-03-10 04:48:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,861 ms / 6,000 ms |
コード長 | 1,467 bytes |
コンパイル時間 | 7,832 ms |
コンパイル使用メモリ | 265,140 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2025-03-10 04:49:18 |
合計ジャッジ時間 | 23,152 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) (void(0)) #endif void run_case(); int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; // cin >> T; while (T--) run_case(); return 0; } void run_case() { int N, M; cin >> N >> M; vector<vector<int>> D(N, vector<int>(M)); for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) cin >> D[i][j]; sort(D[i].begin(), D[i].end()); } auto Check = [&](ll x) -> bool { vector<int> dp(M, 1); for(int it = 1; it < N; it++) { vector<int> ndp(M, 0); vector<int> pref(M + 1); for(int j = 0; j < M; j++) pref[j + 1] = pref[j] + dp[j]; int l = 0, r = 0; for(int j = 0; j < M; j++) { while(l < M && D[it - 1][l] < D[it][j] - x) l++; while(r < M && D[it - 1][r] <= D[it][j]) r++; ndp[j] = (pref[r] - pref[l]) > 0; } swap(dp, ndp); } bool ok = false; for(int j = 0; j < M; j++) if(dp[j]) ok = true; return ok; }; if(Check(0)) { cout << 0 << endl; } else { ll ok = 1e10, ng = 0; while(ok - ng > 1) { ll mi = (ok + ng) / 2; (Check(mi) ? ok : ng) = mi; } cout << (ok == (ll)1e10? -1 : ok) << endl; } }