結果

問題 No.2248 max(C)-min(C)
ユーザー sayan maitisayan maiti
提出日時 2023-03-17 23:52:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 710 ms / 3,000 ms
コード長 5,880 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 215,956 KB
実行使用メモリ 33,528 KB
最終ジャッジ日時 2023-10-18 16:39:35
合計ジャッジ時間 22,461 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 3 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 4 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 593 ms
23,636 KB
testcase_19 AC 38 ms
6,732 KB
testcase_20 AC 710 ms
33,528 KB
testcase_21 AC 661 ms
33,048 KB
testcase_22 AC 393 ms
20,260 KB
testcase_23 AC 196 ms
13,204 KB
testcase_24 AC 59 ms
7,216 KB
testcase_25 AC 601 ms
32,664 KB
testcase_26 AC 514 ms
21,932 KB
testcase_27 AC 578 ms
32,568 KB
testcase_28 AC 27 ms
5,292 KB
testcase_29 AC 506 ms
22,724 KB
testcase_30 AC 138 ms
12,968 KB
testcase_31 AC 664 ms
33,528 KB
testcase_32 AC 65 ms
7,588 KB
testcase_33 AC 120 ms
12,572 KB
testcase_34 AC 679 ms
33,528 KB
testcase_35 AC 686 ms
33,528 KB
testcase_36 AC 675 ms
33,528 KB
testcase_37 AC 265 ms
18,736 KB
testcase_38 AC 618 ms
33,528 KB
testcase_39 AC 607 ms
33,528 KB
testcase_40 AC 618 ms
33,528 KB
testcase_41 AC 479 ms
23,180 KB
testcase_42 AC 609 ms
33,528 KB
testcase_43 AC 510 ms
32,448 KB
testcase_44 AC 590 ms
33,528 KB
testcase_45 AC 423 ms
22,396 KB
testcase_46 AC 160 ms
12,796 KB
testcase_47 AC 602 ms
33,528 KB
testcase_48 AC 250 ms
33,528 KB
testcase_49 AC 574 ms
33,528 KB
testcase_50 AC 583 ms
33,528 KB
testcase_51 AC 593 ms
33,528 KB
testcase_52 AC 586 ms
33,528 KB
testcase_53 AC 51 ms
7,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
Someday at the sound of the night blooming
Simply take away the loneliness from me
Well then, goodbye, my drifting emotions
I'll close my eyes and have a good night. See you tomorrow

At the moment, it's just a little bit hard
I won't cry or something, I'm just trying to walk it off
I don't know what will be on my mind a few minutes later, and I still won't know even today

Wobbly, Wobbly, Wobbly, Wobbly floating
Ah, I'm such a bad child. An inferior student

Is that okay? Is that really okay?
I can't laugh well today, is that okay?
Are you ready? Hey! I said "are you ready?"
Let's just doze off into the warm corners of the night

Is that okay? Ah, Is that really okay?
I don't know what to say, is that okay?
Like that, come on, just like that
I'll dance with you, lalulalila~ See you later

Credits:- MIMI
Song:- Escape
*/


// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
//typedef __int128 bigll;
typedef long long ll;
#define ull unsigned long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define Forl(i,a,b) for(ll (i)=(a);(i) < (b); ++(i))
#define Forn(i,a,b) for(int (i)=(a);(i) >= (b); --(i))
#define Fornl(i,a,b) for(ll (i)=(a);(i) >= (b); --(i))
#define endl "\n"
#define pi 3.14159265
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
const ll mod = 1000 * 1000 * 1000 + 7;
const ll mod1 = 998244353;
const ll INF  = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;


ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x);  // adding powers wherever bit is set
  

        y = y>>1; 

        x = (long long)(x*x); // increasing power by 2

        //cout<<x<<'\n'; 
    } 
    return res; 
} 




// Stolen Templates

template<typename F, typename S>
ostream& operator <<(ostream& ostream, pair<F, S>& p) {
    cout << p.first << " " << p.second;
    return ostream;
}
 
template<typename T>
ostream& operator <<(ostream& ostream, vector<T>& v) {
    for(auto& element : v) {
        cout << element << " ";
    }
    return ostream;
}
 
template<typename T>
ostream& operator <<(ostream& ostream, vector<vector<T>>& v) {
    for(auto& row : v) {
        for(auto& cell : row) {
            cout << cell << " ";
        }
        cout << "\n";
    }
    return ostream;
}
 
template<typename F, typename S>
istream& operator >>(istream& istream, pair<F, S>& p) {
    cin >> p.first >> p.second;
    return istream;
}
 
template<typename T>
istream& operator >>(istream& istream, vector<T>& v) {
    for(auto& element : v) {
        cin >> element;
    }
    return istream;
}

void print() {
    cout << endl;
}

template <typename T> void print(const T& t) {
    cout << t << endl;
}

template <typename First, typename... Rest> void print(const First& first, const Rest&... rest) {
    cout << first << " ";
    print(rest...); // recursive call using pack expansion syntax
}

void dbg() {
    cerr << endl;
}

template <typename T> void dbg(const T& t) {
    cerr << t << endl;
}

template <typename First, typename... Rest> void dbg(const First& first, const Rest&... rest) {
    cerr << first << " ";
    dbg(rest...); // recursive call using pack expansion syntax
}

// Stolen Templates end here

// ostream& operator << (ostream&, bigll val) {
//     string temp;
//     while (val > 0) { temp.pb(val % 10 + '0'); val /= 10; }
//     for(int i = siz(temp) - 1; i >= 0; i--)cout<<temp[i];
//     return cout;
// } // inside class

// istream& operator >> (istream&, bigll & val) {
//     string temp; cin>>temp; val = 0;
//     for(int i = 0; i < siz(temp); i++)val = val * 10 + temp[i] - '0';
//     return cin;
// } // for cin we use & because we want the original object we are sending not a copy of it


int main()
{

// #ifndef ONLINE_JUDGE    
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif


// If you plan on using set / map do check if it will TLE or not
fastio();


    ll n;
    cin>>n;

    vector <ll> a(n),b(n);
    cin>>a>>b;
    vector <ll> used(n);
    vector <pll> vux;
    multiset <ll> sweep;

    For(i,0,n) {
        if (a[i] > b[i])swap(a[i], b[i]);
        sweep.insert(a[i]);
        vux.pb({a[i], i});
        vux.pb({b[i], i});
        vux.pb({(a[i] + b[i]) / 2, i});
    }

    sort(all(vux));
    ll ans = *sweep.rbegin() - *sweep.begin();

    For(i,0,siz(vux)) {
        auto [val, idx] = vux[i];
        used[idx] += 1;

        if (used[idx] != 3) {
            sweep.erase(sweep.find(val));
            if (used[idx] == 1) {
                sweep.insert((a[idx] + b[idx]) / 2);
            }
            if (used[idx] == 2) {
                sweep.insert(b[idx]);
            }
        }
        ans = min(ans, *sweep.rbegin() - *sweep.begin());
    }
    cout<<ans;
    

return 0;
}

// check all product based operations for integer overflow
// careful of renamed variables especially in loops
//python interactive_runner.py python local_testing_tool.py 0 -- c.exe






0