結果

問題 No.2248 max(C)-min(C)
ユーザー bayashikobayashiko
提出日時 2023-03-06 22:23:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,225 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 210,020 KB
実行使用メモリ 15,152 KB
最終ジャッジ日時 2023-10-18 05:18:18
合計ジャッジ時間 7,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_07 AC 2 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 93 ms
10,868 KB
testcase_19 AC 13 ms
4,628 KB
testcase_20 AC 109 ms
15,152 KB
testcase_21 AC 103 ms
14,996 KB
testcase_22 AC 72 ms
10,208 KB
testcase_23 AC 46 ms
6,648 KB
testcase_24 AC 19 ms
4,796 KB
testcase_25 AC 99 ms
14,864 KB
testcase_26 AC 86 ms
10,656 KB
testcase_27 AC 98 ms
14,836 KB
testcase_28 AC 11 ms
4,348 KB
testcase_29 AC 90 ms
10,744 KB
testcase_30 AC 37 ms
6,380 KB
testcase_31 AC 108 ms
15,152 KB
testcase_32 AC 21 ms
4,872 KB
testcase_33 AC 34 ms
6,292 KB
testcase_34 AC 109 ms
15,152 KB
testcase_35 AC 109 ms
15,152 KB
testcase_36 AC 109 ms
15,152 KB
testcase_37 AC 56 ms
9,768 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 63 ms
15,152 KB
testcase_49 AC 105 ms
15,152 KB
testcase_50 AC 106 ms
15,152 KB
testcase_51 AC 106 ms
15,152 KB
testcase_52 AC 105 ms
15,152 KB
testcase_53 AC 18 ms
4,792 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];
    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]);
        }
    }
    cout << maxi-mini << endl;
}
0