結果

問題 No.2248 max(C)-min(C)
ユーザー hiro71687khiro71687k
提出日時 2023-03-18 16:46:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 3,000 ms
コード長 1,237 bytes
コンパイル時間 4,300 ms
コンパイル使用メモリ 268,248 KB
実行使用メモリ 24,596 KB
最終ジャッジ日時 2023-10-18 17:24:28
合計ジャッジ時間 13,420 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 204 ms
15,624 KB
testcase_19 AC 28 ms
5,848 KB
testcase_20 AC 238 ms
24,596 KB
testcase_21 AC 224 ms
24,276 KB
testcase_22 AC 155 ms
14,292 KB
testcase_23 AC 99 ms
10,956 KB
testcase_24 AC 40 ms
6,016 KB
testcase_25 AC 216 ms
24,020 KB
testcase_26 AC 189 ms
15,188 KB
testcase_27 AC 214 ms
23,956 KB
testcase_28 AC 22 ms
4,720 KB
testcase_29 AC 195 ms
15,364 KB
testcase_30 AC 81 ms
10,428 KB
testcase_31 AC 237 ms
24,596 KB
testcase_32 AC 46 ms
6,088 KB
testcase_33 AC 74 ms
10,076 KB
testcase_34 AC 238 ms
24,596 KB
testcase_35 AC 237 ms
24,596 KB
testcase_36 AC 238 ms
24,596 KB
testcase_37 AC 124 ms
13,416 KB
testcase_38 AC 217 ms
24,596 KB
testcase_39 AC 215 ms
24,596 KB
testcase_40 AC 216 ms
24,596 KB
testcase_41 AC 182 ms
15,496 KB
testcase_42 AC 215 ms
24,596 KB
testcase_43 AC 190 ms
23,876 KB
testcase_44 AC 215 ms
24,596 KB
testcase_45 AC 165 ms
15,012 KB
testcase_46 AC 87 ms
10,644 KB
testcase_47 AC 216 ms
24,596 KB
testcase_48 AC 182 ms
24,596 KB
testcase_49 AC 237 ms
24,596 KB
testcase_50 AC 238 ms
24,596 KB
testcase_51 AC 238 ms
24,596 KB
testcase_52 AC 237 ms
24,596 KB
testcase_53 AC 39 ms
6,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.14159265359;
ll inf=1001000000000;
ll mod=1000000007;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(n),b(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    vector<pair<ll,ll>>c;
    for (ll i = 0; i < n; i++)
    {
        c.push_back({a[i],i});
        c.push_back({b[i],i});
        c.push_back({(a[i]+b[i])/2,i});
    }
    sort(c.begin(),c.end());
    vector<ll>memo(n,0);
    ll mi=c[0].first;
    ll now=0;
    ll ans=inf;
    ll st=0;
    for (ll i = 0; i < c.size(); i++)
    {
        if (memo[c[i].second]==0)
        {
            now+=1;
        }
        memo[c[i].second]+=1;
        if (now==n)
        {
            for (ll j = st; j < i; j++)
            {
                if (memo[c[j].second]==1)
                {
                    mi=c[j].first;
                    st=j;
                    break;
                }else{
                    memo[c[j].second]-=1;
                }
            }
            ans=min(ans,c[i].first-mi);
        }
    }
    cout << ans << endl;
}
0