結果

問題 No.2248 max(C)-min(C)
ユーザー bayashikobayashiko
提出日時 2023-03-16 21:15:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,640 bytes
コンパイル時間 2,531 ms
コンパイル使用メモリ 212,452 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2023-10-18 13:12:50
合計ジャッジ時間 45,426 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 9 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 14 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 17 ms
4,348 KB
testcase_09 AC 16 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 9 ms
4,348 KB
testcase_13 AC 12 ms
4,348 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 17 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 16 ms
4,348 KB
testcase_18 AC 1,214 ms
10,884 KB
testcase_19 AC 158 ms
4,644 KB
testcase_20 AC 1,387 ms
15,172 KB
testcase_21 AC 1,317 ms
15,012 KB
testcase_22 AC 919 ms
10,224 KB
testcase_23 AC 589 ms
6,664 KB
testcase_24 AC 233 ms
4,812 KB
testcase_25 AC 1,256 ms
14,880 KB
testcase_26 AC 1,115 ms
10,672 KB
testcase_27 AC 1,246 ms
14,852 KB
testcase_28 AC 125 ms
4,348 KB
testcase_29 AC 1,160 ms
10,760 KB
testcase_30 AC 469 ms
6,396 KB
testcase_31 AC 1,386 ms
15,172 KB
testcase_32 AC 267 ms
4,888 KB
testcase_33 AC 431 ms
6,308 KB
testcase_34 AC 1,389 ms
15,172 KB
testcase_35 AC 1,385 ms
15,172 KB
testcase_36 AC 1,388 ms
15,172 KB
testcase_37 AC 721 ms
9,784 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 1,345 ms
15,172 KB
testcase_49 AC 1,384 ms
15,172 KB
testcase_50 AC 1,384 ms
15,172 KB
testcase_51 AC 1,386 ms
15,172 KB
testcase_52 AC 1,383 ms
15,172 KB
testcase_53 AC 229 ms
4,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
//typedef __int128_t llint;
//#include<atcoder/all>
//using namespace atcoder;

int main(void){
    lint N;
    cin >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    lint ans=1e18;
    vector<lint> md;
    rep(i,N){
        md.push_back(A[i]);
        md.push_back((A[i]+B[i])/2);
        md.push_back(B[i]);
    }
    sort(all(md));
    lint sum=md[3*N/2];
    rep(i,N) if(A[i]>B[i]) swap(A[i],B[i]);
    lint maxi=-1e18,mini=1e18;
    rep(i,N){
        lint dis[3];
        dis[0]=abs(sum-A[i]);
        dis[1]=abs(sum-(A[i]+B[i])/2);
        dis[2]=abs(sum-B[i]);
        lint take=min_element(dis,dis+3)-dis;
        if(take==0){
            chmax(maxi,A[i]);
            chmin(mini,A[i]);
        }
        else if(take==1){
            chmax(maxi,(A[i]+B[i])/2);
            chmin(mini,(A[i]+B[i])/2);
        }
        else{
            chmax(maxi,B[i]);
            chmin(mini,B[i]);
        }
    }
    chmin(ans,maxi-mini);
    int sz=md.size();
    rep(t,min(sz,1000)){
        maxi=-1e18,mini=1e18;
        lint sum=md[t];
        rep(i,N){
            lint dis[3];
            dis[0]=abs(sum-A[i]);
            dis[1]=abs(sum-(A[i]+B[i])/2);
            dis[2]=abs(sum-B[i]);
            lint take=min_element(dis,dis+3)-dis;
            if(take==0){
                chmax(maxi,A[i]);
                chmin(mini,A[i]);
            }
            else if(take==1){
                chmax(maxi,(A[i]+B[i])/2);
                chmin(mini,(A[i]+B[i])/2);
            }
            else{
                chmax(maxi,B[i]);
                chmin(mini,B[i]);
            }
        }
        chmin(ans,maxi-mini);
    }
    reverse(all(md));
    rep(t,min(sz,1000)){
        maxi=-1e18,mini=1e18;
        lint sum=md[t];
        rep(i,N){
            lint dis[3];
            dis[0]=abs(sum-A[i]);
            dis[1]=abs(sum-(A[i]+B[i])/2);
            dis[2]=abs(sum-B[i]);
            lint take=min_element(dis,dis+3)-dis;
            if(take==0){
                chmax(maxi,A[i]);
                chmin(mini,A[i]);
            }
            else if(take==1){
                chmax(maxi,(A[i]+B[i])/2);
                chmin(mini,(A[i]+B[i])/2);
            }
            else{
                chmax(maxi,B[i]);
                chmin(mini,B[i]);
            }
        }
        chmin(ans,maxi-mini);
    }
    cout << ans << endl;
}
0