結果

問題 No.2248 max(C)-min(C)
ユーザー jianglyjiangly
提出日時 2023-03-22 00:02:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 3,000 ms
コード長 979 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 213,848 KB
実行使用メモリ 19,056 KB
最終ジャッジ日時 2023-10-18 18:39:29
合計ジャッジ時間 7,797 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 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 106 ms
11,628 KB
testcase_19 AC 15 ms
5,128 KB
testcase_20 AC 123 ms
17,176 KB
testcase_21 AC 119 ms
19,056 KB
testcase_22 AC 81 ms
11,036 KB
testcase_23 AC 52 ms
7,056 KB
testcase_24 AC 22 ms
5,216 KB
testcase_25 AC 114 ms
18,928 KB
testcase_26 AC 99 ms
11,524 KB
testcase_27 AC 113 ms
18,896 KB
testcase_28 AC 12 ms
4,372 KB
testcase_29 AC 101 ms
11,564 KB
testcase_30 AC 42 ms
8,444 KB
testcase_31 AC 122 ms
17,176 KB
testcase_32 AC 24 ms
5,256 KB
testcase_33 AC 39 ms
8,396 KB
testcase_34 AC 123 ms
17,176 KB
testcase_35 AC 123 ms
17,176 KB
testcase_36 AC 123 ms
17,176 KB
testcase_37 AC 66 ms
10,548 KB
testcase_38 AC 118 ms
17,176 KB
testcase_39 AC 118 ms
17,176 KB
testcase_40 AC 118 ms
17,176 KB
testcase_41 AC 101 ms
11,596 KB
testcase_42 AC 120 ms
17,176 KB
testcase_43 AC 108 ms
18,848 KB
testcase_44 AC 118 ms
17,176 KB
testcase_45 AC 92 ms
11,476 KB
testcase_46 AC 48 ms
7,032 KB
testcase_47 AC 119 ms
17,176 KB
testcase_48 AC 98 ms
17,176 KB
testcase_49 AC 122 ms
17,176 KB
testcase_50 AC 122 ms
17,176 KB
testcase_51 AC 121 ms
17,176 KB
testcase_52 AC 122 ms
17,176 KB
testcase_53 AC 21 ms
5,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;
    std::cin >> N;
    
    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::tuple<int, int, int>> events;
    int r = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] > B[i]) {
            std::swap(A[i], B[i]);
        }
        r = std::max(r, A[i]);
        events.emplace_back(A[i], 1, (A[i] + B[i]) / 2);
        events.emplace_back((A[i] + B[i]) / 2, 2, B[i]);
        events.emplace_back(B[i], 3, -1);
    }
    
    std::sort(events.begin(), events.end());
    int ans = 1E9;
    for (auto [x, t, y] : events) {
        ans = std::min(ans, r - x);
        if (t == 3) {
            break;
        }
        r = std::max(r, y);
    }
    std::cout << ans << "\n";
    
    return 0;
}
0