結果

問題 No.2248 max(C)-min(C)
ユーザー Shell-WataruShell-Wataru
提出日時 2023-03-17 22:15:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,107 bytes
コンパイル時間 1,925 ms
コンパイル使用メモリ 137,304 KB
実行使用メモリ 6,552 KB
最終ジャッジ日時 2023-10-18 15:08:07
合計ジャッジ時間 9,381 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 176 ms
5,980 KB
testcase_19 AC 24 ms
4,348 KB
testcase_20 AC 199 ms
6,508 KB
testcase_21 AC 190 ms
6,244 KB
testcase_22 AC 135 ms
5,452 KB
testcase_23 AC 86 ms
4,660 KB
testcase_24 AC 35 ms
4,348 KB
testcase_25 AC 180 ms
6,244 KB
testcase_26 AC 162 ms
5,980 KB
testcase_27 AC 181 ms
6,244 KB
testcase_28 AC 20 ms
4,348 KB
testcase_29 AC 167 ms
5,980 KB
testcase_30 AC 69 ms
4,396 KB
testcase_31 AC 201 ms
6,508 KB
testcase_32 AC 40 ms
4,348 KB
testcase_33 AC 63 ms
4,396 KB
testcase_34 AC 200 ms
6,508 KB
testcase_35 AC 202 ms
6,508 KB
testcase_36 AC 201 ms
6,508 KB
testcase_37 AC 106 ms
4,924 KB
testcase_38 AC 176 ms
6,508 KB
testcase_39 AC 175 ms
6,508 KB
testcase_40 AC 176 ms
6,508 KB
testcase_41 AC 151 ms
5,980 KB
testcase_42 AC 176 ms
6,508 KB
testcase_43 AC 155 ms
6,244 KB
testcase_44 AC 175 ms
6,508 KB
testcase_45 AC 137 ms
5,716 KB
testcase_46 AC 73 ms
4,660 KB
testcase_47 AC 177 ms
6,508 KB
testcase_48 AC 172 ms
6,508 KB
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <set>
#include <atcoder/string>
#include <unordered_map>
#include <climits>
#include <atcoder/lazysegtree>

using namespace std;
using ll = long long;
using namespace atcoder;

ll value(vector<ll> &A,vector<ll> &B,ll maxC)
{
    ll N = A.size();
    ll minC = numeric_limits<ll>::max();
    for(int i = 0;i < N;i++){
        if (B[i] <= maxC){
            minC = min(minC,B[i]);
            continue;
        }
        if ( (A[i] + B[i])/2 <= maxC){
            minC = min(minC,(A[i] + B[i])/2);
            continue;
        }
        if (A[i] <= maxC){
            minC = min(minC,A[i]);
            continue;
        }
        return numeric_limits<ll>::max();
    }
    return maxC - minC;
}


ll three_search(vector<ll> &A,vector<ll> &B,ll l,ll r)
{
    // cout << l << "~" << r << endl;
    if (l + 2 >= r)
    {
        vector<pair<ll, ll>> values;
        for (int i = l; i < r; i++)
        {
            values.push_back({value(A,B, i), i});
        }
        sort(values.begin(), values.end());
        return values.front().second;
    }
    else
    {
        ll t1 = (2 * l + r) / 3;
        ll t2 = (l + 2 * r) / 3;
        ll t1_value = value(A,B, t1);
        ll t2_value = value(A,B, t2);
        if (t1_value <= t2_value)
        {
            return three_search(A,B, l, t2);
        }
        else
        {
            return three_search(A,B, t1, r);
        }
    }
}

int solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    for(int i = 0;i < N;i++){
        cin >> B[i];
        if (A[i] > B[i]){
            swap(A[i],B[i]);
        }
    }

    ll maxC = three_search(A,B,0,1e10);
    cout << value(A,B,maxC) << endl;
    return 0;
}
int main()
{
    // ll T;
    // cin >> T;
    // while (T--)
    // {
        solve();
    // }
    // cout << flush;
    return 0;
}
0