結果

問題 No.2248 max(C)-min(C)
ユーザー nono00nono00
提出日時 2023-03-18 00:55:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 3,000 ms
コード長 1,242 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 83,772 KB
実行使用メモリ 10,416 KB
最終ジャッジ日時 2023-10-18 16:44:37
合計ジャッジ時間 9,288 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 201 ms
9,624 KB
testcase_19 AC 27 ms
4,348 KB
testcase_20 AC 230 ms
10,416 KB
testcase_21 AC 218 ms
10,152 KB
testcase_22 AC 152 ms
8,108 KB
testcase_23 AC 98 ms
6,260 KB
testcase_24 AC 39 ms
4,676 KB
testcase_25 AC 209 ms
9,624 KB
testcase_26 AC 184 ms
9,096 KB
testcase_27 AC 207 ms
9,624 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 192 ms
9,096 KB
testcase_30 AC 78 ms
5,732 KB
testcase_31 AC 231 ms
10,416 KB
testcase_32 AC 45 ms
4,676 KB
testcase_33 AC 72 ms
5,468 KB
testcase_34 AC 231 ms
10,416 KB
testcase_35 AC 230 ms
10,416 KB
testcase_36 AC 230 ms
10,416 KB
testcase_37 AC 119 ms
6,988 KB
testcase_38 AC 207 ms
10,416 KB
testcase_39 AC 207 ms
10,416 KB
testcase_40 AC 207 ms
10,416 KB
testcase_41 AC 175 ms
9,360 KB
testcase_42 AC 206 ms
10,416 KB
testcase_43 AC 182 ms
9,624 KB
testcase_44 AC 207 ms
10,416 KB
testcase_45 AC 159 ms
8,900 KB
testcase_46 AC 84 ms
6,260 KB
testcase_47 AC 207 ms
10,416 KB
testcase_48 AC 173 ms
10,416 KB
testcase_49 AC 221 ms
10,416 KB
testcase_50 AC 223 ms
10,416 KB
testcase_51 AC 224 ms
10,416 KB
testcase_52 AC 223 ms
10,416 KB
testcase_53 AC 38 ms
4,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> count(n);
    int now = 0;
    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    for (int i = 0; i < n; i++) std::cin >> b[i];
    std::vector<std::pair<int, int>> event(3 * n);
    for (int i = 0; i < n; i++) {
        event[3 * i] = {a[i], i};
        event[3 * i + 1] = {b[i], i};
        event[3 * i + 2] = {(a[i] + b[i]) / 2, i};
    }
    std::sort(event.begin(), event.end());
    auto add = [&](int i) {
        count[event[i].second]++;
        if (count[event[i].second] == 1) {
            now++;
        }
    };
    auto erase = [&](int i) {
        count[event[i].second]--;
        if (count[event[i].second] == 0) {
            now--;
        }
    };
    auto check = [&]() {
        return now == n;
    };
    int r = 0;
    int ans = 1e9;
    for (int l = 0; l < 3 * n; l++) {
        if (r < l) r = l;
        for (; r < 3 * n && !check();) {
            add(r++);
        }
        if (check()) {
            ans = std::min(ans, event[r - 1].first - event[l].first);
        }
        if (l < r) erase(l);
    }
    std::cout << ans << '\n';
}
0