結果

問題 No.2248 max(C)-min(C)
ユーザー kcvlexkcvlex
提出日時 2023-03-17 22:00:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 590 ms / 3,000 ms
コード長 1,581 bytes
コンパイル時間 3,448 ms
コンパイル使用メモリ 170,148 KB
実行使用メモリ 41,544 KB
最終ジャッジ日時 2023-10-18 14:38:01
合計ジャッジ時間 21,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 494 ms
32,212 KB
testcase_19 AC 52 ms
7,668 KB
testcase_20 AC 587 ms
41,544 KB
testcase_21 AC 548 ms
39,268 KB
testcase_22 AC 373 ms
26,728 KB
testcase_23 AC 224 ms
17,364 KB
testcase_24 AC 80 ms
9,108 KB
testcase_25 AC 529 ms
37,948 KB
testcase_26 AC 454 ms
31,864 KB
testcase_27 AC 510 ms
37,780 KB
testcase_28 AC 39 ms
6,628 KB
testcase_29 AC 463 ms
31,092 KB
testcase_30 AC 181 ms
15,012 KB
testcase_31 AC 586 ms
41,544 KB
testcase_32 AC 92 ms
9,976 KB
testcase_33 AC 160 ms
14,224 KB
testcase_34 AC 590 ms
41,544 KB
testcase_35 AC 581 ms
41,544 KB
testcase_36 AC 581 ms
41,544 KB
testcase_37 AC 289 ms
22,976 KB
testcase_38 AC 565 ms
41,544 KB
testcase_39 AC 567 ms
41,544 KB
testcase_40 AC 559 ms
41,544 KB
testcase_41 AC 464 ms
31,552 KB
testcase_42 AC 564 ms
41,544 KB
testcase_43 AC 489 ms
37,524 KB
testcase_44 AC 570 ms
41,544 KB
testcase_45 AC 429 ms
30,776 KB
testcase_46 AC 208 ms
16,972 KB
testcase_47 AC 560 ms
41,544 KB
testcase_48 AC 302 ms
41,544 KB
testcase_49 AC 576 ms
41,544 KB
testcase_50 AC 580 ms
41,544 KB
testcase_51 AC 572 ms
41,544 KB
testcase_52 AC 581 ms
41,544 KB
testcase_53 AC 83 ms
9,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <atcoder/all>

#define ALL(V) std::begin(V), std::end(V)

using ll = long long;

const ll INF = 5e15;

ll op(ll a, ll b) {
    return std::max(a, b);
}

ll e() {
    return -INF;
}

int main() {
    using pll = std::pair<ll, ll>;

    ll N;
    std::cin >> N;
    std::vector<ll> A(N), B(N);
    for (auto &e : A) std::cin >> e;
    for (auto &e : B) std::cin >> e;

    std::vector<std::priority_queue<ll, std::vector<ll>, std::greater<ll>>> pq_v(N);
    std::vector<ll> all;
    for (int i = 0; i < N; i++) {
        ll arr[] = { A[i], B[i], (A[i] + B[i]) / 2 };
        for (auto e : arr) {
            all.push_back(e);
            pq_v[i].push(e);
        }
        pq_v[i].push(INF);
    }

    std::priority_queue<pll, std::vector<pll>, std::greater<pll>> pq;
    std::vector<ll> init(N);
    for (int i = 0; i < N; i++) {
        ll v = pq_v[i].top();
        init[i] = v;
        pq.emplace(v, i);
    }

    atcoder::segtree<ll, op, e> seg(init);

    {
        std::sort(ALL(all));
        auto ite = std::unique(ALL(all));
        all.erase(ite, all.end());
    }

    ll ans = INF;
    for (auto e : all) {
        while (true) {
            auto [ v, i ] = pq.top();
            if (e <= v) break;
            pq.pop();
            pq_v[i].pop();
            ll v2 = pq_v[i].top();
            pq.emplace(v2, i);
            seg.set(i, v2);
        }
        auto max = seg.prod(0, N);
        ans = std::min(ans, max - e);
    }

    std::cout << ans << std::endl;
    return 0;
}
0