結果

問題 No.2248 max(C)-min(C)
ユーザー simansiman
提出日時 2023-03-19 23:13:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 355 ms / 3,000 ms
コード長 1,598 bytes
コンパイル時間 1,286 ms
コンパイル使用メモリ 134,500 KB
実行使用メモリ 23,380 KB
最終ジャッジ日時 2023-10-18 17:55:20
合計ジャッジ時間 13,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 3 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 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 302 ms
19,880 KB
testcase_19 AC 36 ms
5,488 KB
testcase_20 AC 352 ms
23,380 KB
testcase_21 AC 333 ms
22,956 KB
testcase_22 AC 228 ms
18,932 KB
testcase_23 AC 139 ms
11,572 KB
testcase_24 AC 55 ms
6,892 KB
testcase_25 AC 314 ms
22,564 KB
testcase_26 AC 280 ms
19,380 KB
testcase_27 AC 317 ms
22,532 KB
testcase_28 AC 29 ms
5,124 KB
testcase_29 AC 292 ms
19,488 KB
testcase_30 AC 112 ms
11,180 KB
testcase_31 AC 355 ms
23,380 KB
testcase_32 AC 63 ms
6,936 KB
testcase_33 AC 103 ms
11,132 KB
testcase_34 AC 350 ms
23,380 KB
testcase_35 AC 353 ms
23,380 KB
testcase_36 AC 354 ms
23,380 KB
testcase_37 AC 174 ms
13,332 KB
testcase_38 AC 336 ms
23,380 KB
testcase_39 AC 327 ms
23,380 KB
testcase_40 AC 327 ms
23,380 KB
testcase_41 AC 279 ms
19,548 KB
testcase_42 AC 327 ms
23,380 KB
testcase_43 AC 283 ms
22,484 KB
testcase_44 AC 329 ms
23,380 KB
testcase_45 AC 248 ms
19,280 KB
testcase_46 AC 125 ms
11,548 KB
testcase_47 AC 329 ms
23,380 KB
testcase_48 AC 224 ms
23,380 KB
testcase_49 AC 350 ms
23,380 KB
testcase_50 AC 344 ms
23,380 KB
testcase_51 AC 344 ms
23,380 KB
testcase_52 AC 346 ms
23,380 KB
testcase_53 AC 53 ms
6,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int i;
  int c;

  Node(int i = -1, int c = -1) {
    this->i = i;
    this->c = c;
  }

  bool operator>(const Node &n) const {
    return c > n.c;
  }
};

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  vector<int> nums;
  priority_queue <Node, vector<Node>, greater<Node>> pque;
  int cand[N][5];

  for (int i = 0; i < N; ++i) {
    int a = A[i];
    int b = B[i];
    if (a > b) {
      int t = a;
      a = b;
      b = t;
    }

    cand[i][0] = INT_MIN;
    cand[i][1] = a;
    cand[i][2] = (a + b) / 2;
    cand[i][3] = b;
    cand[i][4] = INT_MAX;

    nums.push_back(a);
    nums.push_back(b);
    nums.push_back((a + b) / 2);

    pque.push(Node(i, INT_MIN));
    pque.push(Node(i, a));
    pque.push(Node(i, b));
    pque.push(Node(i, (a + b) / 2));
    pque.push(Node(i, INT_MAX));
  }

  sort(nums.begin(), nums.end());
  vector<int> cur_pos(N, 0);
  int ans = INT_MAX;
  int max_c = 0;

  for (int min_c : nums) {
    while (not pque.empty() && pque.top().c < min_c) {
      Node node = pque.top();
      pque.pop();

      cur_pos[node.i]++;
      max_c = max(max_c, cand[node.i][cur_pos[node.i]]);
    }

    ans = min(ans, max_c - min_c);
  }

  cout << ans << endl;

  return 0;
}
0