結果

問題 No.2248 max(C)-min(C)
ユーザー Shreyan RayShreyan Ray
提出日時 2023-03-17 23:06:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 311 ms / 3,000 ms
コード長 2,071 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 211,268 KB
実行使用メモリ 39,304 KB
最終ジャッジ日時 2023-10-18 16:06:19
合計ジャッジ時間 12,276 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,964 KB
testcase_01 AC 3 ms
9,964 KB
testcase_02 AC 3 ms
9,964 KB
testcase_03 AC 4 ms
10,112 KB
testcase_04 AC 3 ms
10,076 KB
testcase_05 AC 3 ms
10,052 KB
testcase_06 AC 5 ms
10,128 KB
testcase_07 AC 5 ms
10,128 KB
testcase_08 AC 6 ms
10,128 KB
testcase_09 AC 5 ms
10,128 KB
testcase_10 AC 3 ms
10,052 KB
testcase_11 AC 5 ms
10,128 KB
testcase_12 AC 4 ms
10,112 KB
testcase_13 AC 4 ms
10,128 KB
testcase_14 AC 5 ms
10,128 KB
testcase_15 AC 5 ms
10,128 KB
testcase_16 AC 5 ms
10,112 KB
testcase_17 AC 5 ms
10,128 KB
testcase_18 AC 248 ms
26,988 KB
testcase_19 AC 28 ms
14,036 KB
testcase_20 AC 306 ms
39,304 KB
testcase_21 AC 281 ms
39,272 KB
testcase_22 AC 177 ms
26,988 KB
testcase_23 AC 108 ms
19,784 KB
testcase_24 AC 42 ms
16,236 KB
testcase_25 AC 281 ms
39,272 KB
testcase_26 AC 232 ms
26,988 KB
testcase_27 AC 268 ms
39,272 KB
testcase_28 AC 22 ms
11,608 KB
testcase_29 AC 237 ms
26,988 KB
testcase_30 AC 85 ms
19,784 KB
testcase_31 AC 311 ms
39,304 KB
testcase_32 AC 47 ms
16,236 KB
testcase_33 AC 75 ms
19,784 KB
testcase_34 AC 290 ms
39,304 KB
testcase_35 AC 291 ms
39,304 KB
testcase_36 AC 288 ms
39,304 KB
testcase_37 AC 134 ms
24,940 KB
testcase_38 AC 282 ms
39,304 KB
testcase_39 AC 289 ms
39,304 KB
testcase_40 AC 285 ms
39,304 KB
testcase_41 AC 235 ms
26,988 KB
testcase_42 AC 303 ms
39,304 KB
testcase_43 AC 245 ms
39,272 KB
testcase_44 AC 284 ms
39,304 KB
testcase_45 AC 209 ms
26,988 KB
testcase_46 AC 99 ms
19,784 KB
testcase_47 AC 283 ms
39,304 KB
testcase_48 AC 167 ms
39,304 KB
testcase_49 AC 288 ms
39,304 KB
testcase_50 AC 296 ms
39,304 KB
testcase_51 AC 293 ms
39,304 KB
testcase_52 AC 299 ms
39,304 KB
testcase_53 AC 39 ms
16,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 69;
int a[N], b[N], c[N];
int seg[4*N];
int n;

void Build(int l, int r, int pos){
    if (l==r) {
        seg[pos] = a[l];
        return;
    }
    
    int mid = (l+r)/2;
    Build(l, mid, pos*2);
    Build(mid + 1, r, pos*2 + 1);
    
    seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
}

void Update(int l, int r, int pos, int qp){
    if (l==r){
        seg[pos] = min(a[l], min(b[l], c[l]));
        return;
    }
    
    int mid = (l+r)/2;
    if (qp <= mid) Update(l, mid, pos*2, qp);
    else Update(mid + 1, r, pos*2 + 1, qp);
    
    seg[pos] = max(seg[pos * 2], seg[pos * 2 + 1]);
}

void Solve() 
{
    cin>>n;
    for (int i=1; i<=n; i++)
    cin>>a[i];
    for (int i=1; i<=n; i++){
        cin>>c[i];
        if (a[i] > c[i]) swap(a[i], c[i]);
        b[i] = (a[i] + c[i])/2;
    }
    
    Build(1, n, 1);
    
    vector <pair<int, pair<int, int>>> v;
    
    for (int i=1; i<=n; i++){
        v.push_back({a[i], {i, 1}});
        v.push_back({b[i], {i, 2}});
        v.push_back({c[i], {i, 3}});
    }
    
    sort(v.begin(), v.end());
    int ans = INF;
    for (auto x: v){
        ans = min(seg[1] - x.f, ans);
        if (x.s.s == 1){
            a[x.s.f] = INF;
        } else if (x.s.s == 2){
            b[x.s.f] = INF;
        } else c[x.s.f] = INF;
        
        Update(1, n, 1, x.s.f);
    }
    
    cout<<ans<<"\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
   // cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0