結果

問題 No.2248 max(C)-min(C)
ユーザー momoyuumomoyuu
提出日時 2023-10-24 23:02:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 3,000 ms
コード長 1,116 bytes
コンパイル時間 4,628 ms
コンパイル使用メモリ 253,816 KB
実行使用メモリ 13,140 KB
最終ジャッジ日時 2023-10-24 23:02:23
合計ジャッジ時間 12,990 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 3 ms
4,348 KB
testcase_07 AC 3 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 111 ms
9,304 KB
testcase_19 AC 15 ms
4,468 KB
testcase_20 AC 128 ms
13,140 KB
testcase_21 AC 121 ms
13,120 KB
testcase_22 AC 83 ms
8,480 KB
testcase_23 AC 54 ms
6,248 KB
testcase_24 AC 21 ms
4,552 KB
testcase_25 AC 117 ms
13,056 KB
testcase_26 AC 103 ms
8,936 KB
testcase_27 AC 117 ms
12,888 KB
testcase_28 AC 12 ms
4,348 KB
testcase_29 AC 106 ms
9,240 KB
testcase_30 AC 43 ms
5,872 KB
testcase_31 AC 129 ms
13,140 KB
testcase_32 AC 25 ms
4,592 KB
testcase_33 AC 39 ms
5,824 KB
testcase_34 AC 129 ms
13,140 KB
testcase_35 AC 129 ms
13,140 KB
testcase_36 AC 131 ms
13,140 KB
testcase_37 AC 66 ms
8,256 KB
testcase_38 AC 126 ms
13,140 KB
testcase_39 AC 123 ms
13,140 KB
testcase_40 AC 124 ms
13,140 KB
testcase_41 AC 104 ms
9,272 KB
testcase_42 AC 123 ms
13,140 KB
testcase_43 AC 110 ms
13,016 KB
testcase_44 AC 124 ms
13,140 KB
testcase_45 AC 95 ms
8,656 KB
testcase_46 AC 49 ms
6,224 KB
testcase_47 AC 124 ms
13,140 KB
testcase_48 AC 100 ms
13,140 KB
testcase_49 AC 129 ms
13,140 KB
testcase_50 AC 127 ms
13,140 KB
testcase_51 AC 128 ms
13,140 KB
testcase_52 AC 129 ms
13,140 KB
testcase_53 AC 21 ms
4,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    for(int i = 0;i<n;i++) cin>>b[i];
    vector<pair<int,int>> use;
    for(int i = 0;i<n;i++){
        use.push_back(make_pair(a[i],i));
        use.push_back(make_pair(b[i],i));
        use.push_back(make_pair((a[i]+b[i])/2,i));
    }
    int cnt = 0;
    vector<int> now(n,0);
    int ans = 1e9;
    sort(use.begin(),use.end());
    int l = 0,r = 0;
    while(l<use.size()){
        while(l>=r){
            int ni = use[r].second;
            now[ni]++;
            if(now[ni]==1) cnt++;
            r++;
        }
        while(cnt!=n&&r<use.size()){
            int ni = use[r].second;
            now[ni]++;
            if(now[ni]==1) cnt++;
            r++;
        }
        if(cnt==n){
            ans = min(ans,use[r-1].first-use[l].first);
        }
        int ni = use[l].second;
        now[ni]--;
        if(now[ni]==0) cnt--;
        l++;
    }
    cout<<ans<<endl;
}

0