結果
問題 |
No.2157 崖
|
ユーザー |
|
提出日時 | 2024-04-03 23:34:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,206 bytes |
コンパイル時間 | 2,513 ms |
コンパイル使用メモリ | 206,040 KB |
最終ジャッジ日時 | 2025-02-20 19:59:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 TLE * 5 -- * 5 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/segtree> using namespace std; using namespace atcoder; using ll = long long; int op(int a, int b) {return max(a, b);} int e() {return 0;} int main() { int N, M;cin >> N >> M; vector<vector<int>> D(N + 1, vector<int>(M + 1, 0)); for (int i = 1;i <= N;i++) { for (int j = 1;j <= M;j++) cin >> D[i][j]; sort(D[i].begin(), D[i].end()); } int inf = (1e9) + 100; int ok = inf; int ng = -1; while (ok - ng > 1) { int X = (ok + ng) / 2; vector<int> d(M + 1, 1);d[0] = 0; segtree<int, op, e> dp(d); for (int i = 2;i <= N;i++) { vector<int> ndp(M + 1, 0); for (int j = 1;j <= M;j++) { int now = D[i][j]; auto itr = lower_bound(D[i - 1].begin(), D[i - 1].end(), now - X); if (itr == D[i - 1].end()) continue; int L = itr - D[i - 1].begin(); auto itr2 = upper_bound(D[i - 1].begin(), D[i - 1].end(), now); if (itr2 == D[i - 1].begin()) continue; itr2--; int R = itr2 - D[i - 1].begin(); if (R < L) continue; ndp[j] = dp.prod(L, R + 1); } for (int j = 1;j <= M;j++) dp.set(j, ndp[j]); } if (dp.prod(0, M + 1) == 1) { ok = X; } else { ng = X; } } cout << (ok == inf ? -1 : ok)<< endl; }