結果

問題 No.2248 max(C)-min(C)
ユーザー hikaririhikariri
提出日時 2023-03-17 22:31:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,500 ms / 3,000 ms
コード長 1,776 bytes
コンパイル時間 5,349 ms
コンパイル使用メモリ 242,116 KB
実行使用メモリ 99,476 KB
最終ジャッジ日時 2023-10-18 15:27:56
合計ジャッジ時間 40,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 6 ms
4,544 KB
testcase_07 AC 6 ms
4,692 KB
testcase_08 AC 7 ms
4,692 KB
testcase_09 AC 7 ms
4,692 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 7 ms
4,692 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 5 ms
4,400 KB
testcase_14 AC 7 ms
4,692 KB
testcase_15 AC 7 ms
4,692 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 7 ms
4,620 KB
testcase_18 AC 1,142 ms
87,332 KB
testcase_19 AC 98 ms
14,588 KB
testcase_20 AC 1,310 ms
99,476 KB
testcase_21 AC 1,229 ms
94,724 KB
testcase_22 AC 784 ms
67,004 KB
testcase_23 AC 447 ms
44,300 KB
testcase_24 AC 135 ms
19,496 KB
testcase_25 AC 1,147 ms
90,500 KB
testcase_26 AC 1,010 ms
80,732 KB
testcase_27 AC 1,130 ms
89,708 KB
testcase_28 AC 67 ms
12,300 KB
testcase_29 AC 1,157 ms
83,372 KB
testcase_30 AC 394 ms
35,852 KB
testcase_31 AC 1,294 ms
99,476 KB
testcase_32 AC 177 ms
21,860 KB
testcase_33 AC 299 ms
33,212 KB
testcase_34 AC 1,313 ms
99,476 KB
testcase_35 AC 1,375 ms
99,476 KB
testcase_36 AC 1,322 ms
99,476 KB
testcase_37 AC 576 ms
53,276 KB
testcase_38 AC 1,264 ms
91,820 KB
testcase_39 AC 1,326 ms
91,820 KB
testcase_40 AC 1,275 ms
91,820 KB
testcase_41 AC 1,053 ms
79,676 KB
testcase_42 AC 1,289 ms
91,820 KB
testcase_43 AC 1,119 ms
82,316 KB
testcase_44 AC 1,325 ms
91,820 KB
testcase_45 AC 952 ms
73,340 KB
testcase_46 AC 450 ms
41,396 KB
testcase_47 AC 1,291 ms
91,820 KB
testcase_48 AC 587 ms
61,988 KB
testcase_49 AC 1,431 ms
99,476 KB
testcase_50 AC 1,478 ms
99,476 KB
testcase_51 AC 1,500 ms
99,476 KB
testcase_52 AC 1,462 ms
99,476 KB
testcase_53 AC 160 ms
19,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
#endif
typedef long long  ll;
typedef pair<int,int> pii; typedef pair<ll,ll> pll;
const int INF = 1e9; const long long LINF = 1e18;
const int MOD = 998244353; const int MOD1 = 1e9+7;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(x) x.begin(), x.end()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
void yorn(bool ans){cout << (ans?"Yes":"No") << endl; return;}

int main(){
    // 尺取法
    int n; cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a.at(i);
    rep(i,n) cin >> b.at(i);

    map<int,set<int>> m;
    rep(i,n){
        m[a.at(i)].insert(i);
        m[b.at(i)].insert(i);
        m[(a.at(i)+b.at(i))/2].insert(i);
    }

    vector<int> num(n);
    set<int> aru;

    auto l = m.begin();
    auto r = m.begin();
    for(auto i:l->second){
        num.at(i)++;
        aru.insert(i);
    }
    
    //rep(i,n) cout << num.at(i) << ' ';
    ll ans = LINF;
    for(;l!=m.end();l++){
        //int f = i.first;
        //auto s = i.second;
        bool ok = true;
        while((int)aru.size()<n){
            r++;
            if(r==m.end()){
                ok = false; break;
            }
            for(auto j:r->second){
                num.at(j)++;
                aru.insert(j);
            }
        }
        if(!ok) break;
        ans = min(ans,(ll)(r->first)-(ll)(l->first));
        for(auto j:l->second){
            num.at(j)--;
            if(num.at(j)==0) aru.erase(j);
        }
    }
    cout << ans << endl;
    //cout << 999 << endl;
}
0