結果

問題 No.2248 max(C)-min(C)
ユーザー AngrySadEightAngrySadEight
提出日時 2023-03-11 00:52:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 3,000 ms
コード長 3,686 bytes
コンパイル時間 8,224 ms
コンパイル使用メモリ 312,420 KB
実行使用メモリ 27,896 KB
最終ジャッジ日時 2023-10-18 09:24:42
合計ジャッジ時間 19,176 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 2 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 180 ms
24,896 KB
testcase_19 AC 25 ms
6,332 KB
testcase_20 AC 204 ms
27,896 KB
testcase_21 AC 197 ms
26,728 KB
testcase_22 AC 140 ms
21,524 KB
testcase_23 AC 90 ms
13,840 KB
testcase_24 AC 37 ms
7,988 KB
testcase_25 AC 187 ms
25,736 KB
testcase_26 AC 166 ms
25,056 KB
testcase_27 AC 187 ms
25,584 KB
testcase_28 AC 20 ms
5,916 KB
testcase_29 AC 172 ms
25,772 KB
testcase_30 AC 73 ms
12,364 KB
testcase_31 AC 204 ms
27,896 KB
testcase_32 AC 42 ms
8,400 KB
testcase_33 AC 65 ms
10,448 KB
testcase_34 AC 204 ms
27,896 KB
testcase_35 AC 206 ms
27,896 KB
testcase_36 AC 204 ms
27,896 KB
testcase_37 AC 108 ms
16,476 KB
testcase_38 AC 267 ms
27,896 KB
testcase_39 AC 271 ms
27,896 KB
testcase_40 AC 273 ms
27,896 KB
testcase_41 AC 233 ms
24,252 KB
testcase_42 AC 270 ms
27,896 KB
testcase_43 AC 242 ms
25,080 KB
testcase_44 AC 273 ms
27,896 KB
testcase_45 AC 210 ms
24,352 KB
testcase_46 AC 103 ms
13,572 KB
testcase_47 AC 276 ms
27,896 KB
testcase_48 AC 208 ms
27,896 KB
testcase_49 AC 352 ms
27,896 KB
testcase_50 AC 354 ms
27,896 KB
testcase_51 AC 349 ms
27,896 KB
testcase_52 AC 347 ms
27,896 KB
testcase_53 AC 47 ms
7,956 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];
    /*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