結果

問題 No.2248 max(C)-min(C)
ユーザー SSRSSSRS
提出日時 2023-03-17 21:31:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 3,000 ms
コード長 932 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 176,240 KB
実行使用メモリ 15,288 KB
最終ジャッジ日時 2023-10-18 13:59:49
合計ジャッジ時間 10,622 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 2 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 197 ms
10,904 KB
testcase_19 AC 26 ms
4,528 KB
testcase_20 AC 227 ms
13,196 KB
testcase_21 AC 216 ms
15,288 KB
testcase_22 AC 150 ms
10,048 KB
testcase_23 AC 96 ms
6,308 KB
testcase_24 AC 39 ms
4,612 KB
testcase_25 AC 206 ms
14,952 KB
testcase_26 AC 182 ms
10,536 KB
testcase_27 AC 204 ms
14,920 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 189 ms
10,576 KB
testcase_30 AC 77 ms
5,932 KB
testcase_31 AC 227 ms
13,196 KB
testcase_32 AC 44 ms
4,652 KB
testcase_33 AC 71 ms
5,884 KB
testcase_34 AC 228 ms
13,196 KB
testcase_35 AC 228 ms
13,196 KB
testcase_36 AC 227 ms
13,196 KB
testcase_37 AC 118 ms
9,824 KB
testcase_38 AC 204 ms
13,196 KB
testcase_39 AC 206 ms
13,196 KB
testcase_40 AC 204 ms
13,196 KB
testcase_41 AC 173 ms
10,872 KB
testcase_42 AC 204 ms
13,196 KB
testcase_43 AC 182 ms
14,872 KB
testcase_44 AC 206 ms
13,196 KB
testcase_45 AC 158 ms
10,488 KB
testcase_46 AC 83 ms
6,284 KB
testcase_47 AC 205 ms
13,196 KB
testcase_48 AC 176 ms
13,196 KB
testcase_49 AC 224 ms
13,196 KB
testcase_50 AC 225 ms
13,196 KB
testcase_51 AC 225 ms
13,196 KB
testcase_52 AC 224 ms
13,196 KB
testcase_53 AC 38 ms
4,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  vector<pair<int, int>> P;
  for (int i = 0; i < N; i++){
    P.push_back(make_pair(A[i], i));
    P.push_back(make_pair(B[i], i));
    P.push_back(make_pair((A[i] + B[i]) / 2, i));
  }
  sort(P.begin(), P.end());
  vector<int> cnt(N, 0);
  cnt[P[0].second]++;
  int cnt2 = 1;
  int L = 0, R = 0;
  int ans = INF;
  while (true){
    if (cnt2 == N){
      ans = min(ans, P[R].first - P[L].first);
      cnt[P[L].second]--;
      if (cnt[P[L].second] == 0){
        cnt2--;
      }
      L++;
    } else {
      R++;
      if (R == N * 3){
        break;
      }
      if (cnt[P[R].second] == 0){
        cnt2++;
      }
      cnt[P[R].second]++;
    }
  }
  cout << ans << endl;
}
0