結果

問題 No.2248 max(C)-min(C)
ユーザー bayashikobayashiko
提出日時 2023-03-06 19:02:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 3,000 ms
コード長 2,299 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 216,024 KB
実行使用メモリ 31,816 KB
最終ジャッジ日時 2023-10-18 05:18:46
合計ジャッジ時間 12,869 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 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 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 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 272 ms
27,652 KB
testcase_19 AC 28 ms
6,292 KB
testcase_20 AC 307 ms
31,816 KB
testcase_21 AC 291 ms
29,220 KB
testcase_22 AC 201 ms
24,284 KB
testcase_23 AC 117 ms
14,436 KB
testcase_24 AC 41 ms
8,212 KB
testcase_25 AC 282 ms
28,752 KB
testcase_26 AC 242 ms
26,636 KB
testcase_27 AC 280 ms
28,660 KB
testcase_28 AC 22 ms
5,776 KB
testcase_29 AC 251 ms
26,948 KB
testcase_30 AC 89 ms
13,228 KB
testcase_31 AC 304 ms
31,816 KB
testcase_32 AC 49 ms
8,476 KB
testcase_33 AC 82 ms
11,080 KB
testcase_34 AC 307 ms
31,816 KB
testcase_35 AC 304 ms
31,816 KB
testcase_36 AC 307 ms
31,816 KB
testcase_37 AC 149 ms
17,056 KB
testcase_38 AC 300 ms
31,816 KB
testcase_39 AC 305 ms
31,816 KB
testcase_40 AC 303 ms
31,816 KB
testcase_41 AC 255 ms
27,444 KB
testcase_42 AC 303 ms
31,816 KB
testcase_43 AC 268 ms
28,504 KB
testcase_44 AC 302 ms
31,816 KB
testcase_45 AC 228 ms
26,064 KB
testcase_46 AC 107 ms
14,264 KB
testcase_47 AC 302 ms
31,816 KB
testcase_48 AC 164 ms
31,816 KB
testcase_49 AC 300 ms
31,816 KB
testcase_50 AC 309 ms
31,816 KB
testcase_51 AC 301 ms
31,816 KB
testcase_52 AC 302 ms
31,816 KB
testcase_53 AC 40 ms
8,192 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){
    int N;
    cin >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) if(A[i]>B[i]) swap(A[i],B[i]);
    lint C[N][5];
    rep(i,N){
        C[i][0]=-1e18;
        C[i][1]=A[i];
        C[i][2]=(A[i]+B[i])/2;
        C[i][3]=B[i];
        C[i][4]=1e18;
    }
    lint ans=2e18;
    vector<lint> mini;
    rep(i,N) for(int j=1;j<=3;j++) mini.push_back(C[i][j]);
    sort(all(mini));
    priority_queue<pair<lint,plint>,vector<pair<lint,plint>>,greater<pair<lint,plint>>> pq;
    rep(i,N) pq.push({C[i][0],{i,0}});
    lint now_maxi=-2e18;
    for(auto e:mini){
        lint now_mini=e;
        while(pq.top().fi<now_mini){
            pair<lint,plint> np=pq.top();
            pq.pop();
            np.se.se++;
            np.fi=C[np.se.fi][np.se.se];
            pq.push(np);
            chmax(now_maxi,np.fi);
        }
        chmin(ans,now_maxi-now_mini);
    }
    cout << ans << endl;
}
0