結果

問題 No.2248 max(C)-min(C)
ユーザー kumakumakumakuma
提出日時 2023-03-13 04:53:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 523 ms / 3,000 ms
コード長 1,588 bytes
コンパイル時間 4,249 ms
コンパイル使用メモリ 208,832 KB
実行使用メモリ 18,800 KB
最終ジャッジ日時 2023-10-18 10:53:47
合計ジャッジ時間 17,837 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 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 409 ms
16,952 KB
testcase_19 AC 29 ms
5,072 KB
testcase_20 AC 510 ms
18,800 KB
testcase_21 AC 446 ms
18,008 KB
testcase_22 AC 285 ms
13,520 KB
testcase_23 AC 139 ms
9,824 KB
testcase_24 AC 45 ms
5,864 KB
testcase_25 AC 443 ms
17,480 KB
testcase_26 AC 369 ms
15,896 KB
testcase_27 AC 412 ms
17,216 KB
testcase_28 AC 22 ms
4,764 KB
testcase_29 AC 391 ms
16,160 KB
testcase_30 AC 98 ms
8,504 KB
testcase_31 AC 523 ms
18,800 KB
testcase_32 AC 52 ms
6,144 KB
testcase_33 AC 92 ms
8,240 KB
testcase_34 AC 486 ms
18,800 KB
testcase_35 AC 479 ms
18,800 KB
testcase_36 AC 517 ms
18,800 KB
testcase_37 AC 188 ms
11,408 KB
testcase_38 AC 451 ms
18,800 KB
testcase_39 AC 430 ms
18,800 KB
testcase_40 AC 433 ms
18,800 KB
testcase_41 AC 335 ms
16,688 KB
testcase_42 AC 435 ms
18,800 KB
testcase_43 AC 391 ms
16,952 KB
testcase_44 AC 428 ms
18,800 KB
testcase_45 AC 307 ms
15,368 KB
testcase_46 AC 119 ms
9,560 KB
testcase_47 AC 425 ms
18,800 KB
testcase_48 AC 207 ms
18,800 KB
testcase_49 AC 423 ms
18,800 KB
testcase_50 AC 409 ms
18,800 KB
testcase_51 AC 423 ms
18,800 KB
testcase_52 AC 419 ms
18,800 KB
testcase_53 AC 41 ms
5,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const double PI = 3.141592653589793;

bool cmp1(pll a, pll b) {
  return a.first + a.second < b.first + b.second;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    cin >> B.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    if (A.at(i) > B.at(i)) {
      swap(A.at(i), B.at(i));
    }
  }
  if (N == 1) {
    cout << 0 << "\n";
    return 0;
  }
  multiset<pll> st;
  for (ll i = 0; i < N; ++i) {
    st.insert({A.at(i), i});
  }
  ll m = INF;
  ll ans = (*st.rbegin()).first - min(m, ((*st.begin()).first));
  while (!st.empty()) {
    pll now = *st.begin();
    st.erase(st.begin());
    ll a = now.first, index = now.second;
    if (a == B.at(index)) {
      m = min(m, a);
    }
    else if (a * 2 == A.at(index) + B.at(index)) {
      st.insert({B.at(index), index});
    }
    else {
      st.insert({(A.at(index) + B.at(index)) / 2, index});
    }
    if (!st.empty()) {
      ans = min(ans, (*st.rbegin()).first - min(m, ((*st.begin()).first)));
    }
  }
  cout << ans << "\n";
}
0