結果

問題 No.2157 崖
ユーザー MazesobaMazesoba
提出日時 2022-12-09 22:33:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,978 bytes
コンパイル時間 5,303 ms
コンパイル使用メモリ 260,616 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-22 22:37:56
合計ジャッジ時間 12,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 769 ms
18,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 658 ms
15,872 KB
testcase_18 AC 653 ms
15,360 KB
testcase_19 WA -
testcase_20 AC 844 ms
19,456 KB
testcase_21 AC 847 ms
19,328 KB
testcase_22 AC 614 ms
14,976 KB
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0