結果

問題 No.2248 max(C)-min(C)
ユーザー hourenhouren
提出日時 2023-03-17 23:10:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 3,000 ms
コード長 1,189 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 180,996 KB
実行使用メモリ 18,284 KB
最終ジャッジ日時 2023-10-18 16:09:21
合計ジャッジ時間 7,228 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 2 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 2 ms
4,348 KB
testcase_18 AC 64 ms
16,924 KB
testcase_19 AC 10 ms
5,100 KB
testcase_20 AC 74 ms
17,320 KB
testcase_21 AC 70 ms
18,284 KB
testcase_22 AC 51 ms
13,624 KB
testcase_23 AC 33 ms
9,588 KB
testcase_24 AC 15 ms
6,060 KB
testcase_25 AC 67 ms
17,556 KB
testcase_26 AC 62 ms
15,908 KB
testcase_27 AC 67 ms
17,460 KB
testcase_28 AC 9 ms
4,840 KB
testcase_29 AC 62 ms
16,488 KB
testcase_30 AC 27 ms
8,644 KB
testcase_31 AC 75 ms
17,320 KB
testcase_32 AC 16 ms
6,324 KB
testcase_33 AC 25 ms
7,628 KB
testcase_34 AC 75 ms
17,320 KB
testcase_35 AC 76 ms
17,320 KB
testcase_36 AC 75 ms
17,320 KB
testcase_37 AC 40 ms
10,632 KB
testcase_38 AC 153 ms
17,320 KB
testcase_39 AC 156 ms
17,320 KB
testcase_40 AC 151 ms
17,320 KB
testcase_41 AC 128 ms
16,720 KB
testcase_42 AC 155 ms
17,320 KB
testcase_43 AC 133 ms
17,040 KB
testcase_44 AC 153 ms
17,320 KB
testcase_45 AC 114 ms
15,600 KB
testcase_46 AC 54 ms
9,420 KB
testcase_47 AC 152 ms
17,320 KB
testcase_48 AC 107 ms
17,320 KB
testcase_49 AC 210 ms
17,320 KB
testcase_50 AC 209 ms
17,320 KB
testcase_51 AC 212 ms
17,320 KB
testcase_52 AC 211 ms
17,320 KB
testcase_53 AC 25 ms
6,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ma = 0, ans = INF;
    priority_queue<asc(T)> pq;
    vector<vector<int>> a(n,vector<int>(3));
    rep(i,n) cin >> a[i][0];
    rep(i,n){
        cin >> a[i][2];
        if(a[i][2]<a[i][0]) swap(a[i][2], a[i][0]);
        a[i][1] = (a[i][0] + a[i][2]) / 2;
        pq.push({a[i][0], i, 0});
        chmax(ma, a[i][0]);
    }
    while(1){
        int p,q,r;
        tie(p,q,r) = pq.top();
        pq.pop();
        chmin(ans, ma-p);
        if(r==2) break;
        pq.push({a[q][r+1],q,r+1});
        chmax(ma, a[q][r+1]);
    }
    cout << ans << '\n';
    return 0;
}
0