結果

問題 No.2248 max(C)-min(C)
ユーザー みここみここ
提出日時 2023-03-17 22:01:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 561 ms / 3,000 ms
コード長 928 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 79,860 KB
実行使用メモリ 14,524 KB
最終ジャッジ日時 2023-10-18 14:45:44
合計ジャッジ時間 11,240 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 5 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 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 230 ms
13,148 KB
testcase_19 AC 27 ms
4,836 KB
testcase_20 AC 261 ms
14,524 KB
testcase_21 AC 254 ms
13,984 KB
testcase_22 AC 160 ms
10,840 KB
testcase_23 AC 100 ms
8,240 KB
testcase_24 AC 39 ms
5,432 KB
testcase_25 AC 233 ms
13,520 KB
testcase_26 AC 210 ms
12,396 KB
testcase_27 AC 234 ms
13,424 KB
testcase_28 AC 21 ms
4,572 KB
testcase_29 AC 216 ms
12,712 KB
testcase_30 AC 80 ms
7,300 KB
testcase_31 AC 262 ms
14,524 KB
testcase_32 AC 45 ms
5,696 KB
testcase_33 AC 72 ms
7,000 KB
testcase_34 AC 279 ms
14,524 KB
testcase_35 AC 275 ms
14,524 KB
testcase_36 AC 267 ms
14,524 KB
testcase_37 AC 128 ms
9,284 KB
testcase_38 AC 251 ms
14,524 KB
testcase_39 AC 245 ms
14,524 KB
testcase_40 AC 244 ms
14,524 KB
testcase_41 AC 206 ms
12,944 KB
testcase_42 AC 239 ms
14,524 KB
testcase_43 AC 211 ms
13,268 KB
testcase_44 AC 241 ms
14,524 KB
testcase_45 AC 176 ms
12,088 KB
testcase_46 AC 88 ms
8,072 KB
testcase_47 AC 240 ms
14,524 KB
testcase_48 AC 309 ms
14,524 KB
testcase_49 AC 558 ms
14,524 KB
testcase_50 AC 553 ms
14,524 KB
testcase_51 AC 561 ms
14,524 KB
testcase_52 AC 542 ms
14,524 KB
testcase_53 AC 60 ms
5,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int a[200005], b[200005];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    set<P> st;
    for (int i = 0; i < n; i++)
    {
        if (a[i] > b[i])
        {
            swap(a[i], b[i]);
        }
        st.insert(P(b[i], i));
    }
    int ans = st.rbegin()->first - st.begin()->first;
    while (true)
    {
        P p = *st.rbegin();
        st.erase(p);
        int i = p.second;
        if (p.first == a[i])
        {
            break;
        }
        if (p.first == b[i])
        {
            st.insert(P((a[i] + b[i]) / 2, i));
        }
        else
        {
            st.insert(P(a[i], i));
        }
        ans = min(ans, st.rbegin()->first - st.begin()->first);
    }
    cout << ans << endl;
}
0