結果

問題 No.2248 max(C)-min(C)
ユーザー AngrySadEightAngrySadEight
提出日時 2023-03-11 00:56:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 3,000 ms
コード長 3,919 bytes
コンパイル時間 9,780 ms
コンパイル使用メモリ 310,692 KB
実行使用メモリ 27,912 KB
最終ジャッジ日時 2023-10-18 09:25:23
合計ジャッジ時間 15,817 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 3 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 181 ms
24,912 KB
testcase_19 AC 26 ms
6,348 KB
testcase_20 AC 204 ms
27,912 KB
testcase_21 AC 197 ms
26,744 KB
testcase_22 AC 140 ms
21,540 KB
testcase_23 AC 90 ms
13,856 KB
testcase_24 AC 37 ms
8,004 KB
testcase_25 AC 187 ms
25,752 KB
testcase_26 AC 167 ms
25,072 KB
testcase_27 AC 187 ms
25,600 KB
testcase_28 AC 21 ms
5,932 KB
testcase_29 AC 172 ms
25,788 KB
testcase_30 AC 73 ms
12,380 KB
testcase_31 AC 204 ms
27,912 KB
testcase_32 AC 42 ms
8,416 KB
testcase_33 AC 66 ms
10,464 KB
testcase_34 AC 203 ms
27,912 KB
testcase_35 AC 204 ms
27,912 KB
testcase_36 AC 204 ms
27,912 KB
testcase_37 AC 108 ms
16,492 KB
testcase_38 AC 275 ms
27,912 KB
testcase_39 AC 275 ms
27,912 KB
testcase_40 AC 275 ms
27,912 KB
testcase_41 AC 235 ms
24,268 KB
testcase_42 AC 276 ms
27,912 KB
testcase_43 AC 248 ms
25,096 KB
testcase_44 AC 274 ms
27,912 KB
testcase_45 AC 212 ms
24,368 KB
testcase_46 AC 104 ms
13,588 KB
testcase_47 AC 272 ms
27,912 KB
testcase_48 AC 207 ms
27,912 KB
testcase_49 AC 354 ms
27,912 KB
testcase_50 AC 359 ms
27,912 KB
testcase_51 AC 357 ms
27,912 KB
testcase_52 AC 358 ms
27,912 KB
testcase_53 AC 47 ms
7,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvpii vector<vector<pair<int,int>>>
#define vvpll vector<vector<pair<ll,ll>>>

template<typename T> void debug(T e){
    cerr << e << endl;
}

template<typename T> void debug(vector<T> &v){
    rep(i, v.size()){
        cerr << v[i] << " ";
    }
    cerr << endl;
}

template<typename T> void debug(vector<vector<T>> &v){
    rep(i, v.size()){
        rep(j, v[i].size()){
            cerr << v[i][j] << " ";
        }
        cerr << endl;
    }
}

template<typename T> void debug(vector<pair<T, T>> &v){
    rep(i,v.size()){
        cerr << v[i].first << " " << v[i].second << endl;
    }
}

template<typename T> void debug(set<T> &st){
    for (auto itr = st.begin(); itr != st.end(); itr++){
        cerr << *itr << " ";
    }
    cerr << endl;
}

template<typename T> void debug(multiset<T> &ms){
    for (auto itr = ms.begin(); itr != ms.end(); itr++){
        cerr << *itr << " ";
    }
    cerr << endl;
}

template<typename T> void debug(map<T, T> &mp){
    for (auto itr = mp.begin(); itr != mp.end(); itr++){
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out(){
    cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
    cerr << H << " ";
    debug_out(T...);
}

int main(){
    ll N;
    cin >> N;
    vl A(N);
    vl B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    assert(1 <= N && N <= 200000);
    for (ll i = 0; i < N; i++){
        assert(0 <= A[i] && A[i] <= 1000000000);
        assert(0 <= B[i] && B[i] <= 1000000000);
        assert(A[i] % 2 == 0);
        assert(B[i] % 2 == 0);
    }
    /*vvpll C(N, vpll(0));
    for (ll i = 0; i < N; i++){
        C.push_back(pll(A[i], i));
        C.push_back(pll(B[i], i));
        C.push_back(pll((A[i] + B[i]) / 2, i));
    }
    sort(all(C));*/
    vvl vec(N, vl(0));
    for (ll i = 0; i < N; i++){
        vec[i].push_back(A[i]);
        vec[i].push_back(B[i]);
        vec[i].push_back((A[i] + B[i]) / 2);
    }
    for (ll i = 0; i < N; i++){
        sort(all(vec[i]));
    }
    priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> pque;
    ll max_val = 0;
    ll min_val = 1000000001;
    for (ll i = 0; i < N; i++){
        pque.push(tuple<ll, ll, ll>(vec[i][0], i, 0));
        max_val = max(max_val, vec[i][0]);
        min_val = min(min_val, vec[i][0]);
    }
    ll ans = max_val - min_val;
    while(true){
        tuple<ll, ll, ll> t = pque.top();
        pque.pop();
        ll val = get<0>(t);
        ll idx = get<1>(t);
        ll order = get<2>(t);
        if (order == 2){
            break;
        }
        pque.push(tuple<ll, ll, ll>(vec[idx][order + 1], idx, order + 1));
        max_val = max(max_val, vec[idx][order + 1]);
        tuple<ll, ll, ll> t2 = pque.top();
        min_val = get<0>(t2);
        ans = min(ans, max_val - min_val);
        //debug_out(max_val, min_val);
    }
    cout << ans << endl;
}
0