結果
問題 |
No.2157 崖
|
ユーザー |
|
提出日時 | 2022-12-09 22:33:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,978 bytes |
コンパイル時間 | 6,645 ms |
コンパイル使用メモリ | 257,404 KB |
最終ジャッジ日時 | 2025-02-09 08:33:34 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 12 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(), x.end() using ll = long long; using ull = unsigned long long; const int INF = 1100100100; const ll INFLL = 1100100100100100100; int main() { int N, M; cin >> N >> M; vector<vector<ll>> D(N, vector<ll>(M)); rep(i, N) { rep(j, M) { cin >> D[i][j]; } sort(ALL(D[i])); } auto test = [&](ll x) { P("x: %lld\n", x); function<bool(ll, ll, int)> f = [&](ll l, ll r, int di) { P("ll: %lld, rr: %lld, di: %d\n", l, r, di); if (di == N) return true; auto ll = l + x; auto rr = r + x; auto fl = upper_bound(ALL(D[di]), ll); auto fr = upper_bound(ALL(D[di]), rr); if (fl == D[di].begin()) return false; if (fr == D[di].begin()) return false; fl--; fr--; if (*fl < l || *fr < r) return false; return f(*fl, *fr, di + 1); }; deque<ll> s; int l = 0; for (int r = 1; r <= N; ++r) { if (r == N || D[0][r] - D[0][l] > x) { auto result = f(D[0][l], D[0][r - 1], 1); if (result) return true; } if (r == N) break; while (D[0][r] - D[0][l] > x) { l++; } } return false; }; ll ng = -1, ok = INFLL; // ll ng = -1, ok = 1; while (ok - ng != 1) { auto m = (ok + ng) / 2; if (test(m)) { ok = m; } else ng = m; } cout << (ok == INFLL ? -1 : ok) << endl; return 0; }