結果

問題 No.837 Noelちゃんと星々2
ユーザー cotton_fn_cotton_fn_
提出日時 2019-06-14 22:49:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,413 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 117,072 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-09-02 07:21:55
合計ジャッジ時間 2,927 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
4,648 KB
testcase_01 AC 48 ms
4,564 KB
testcase_02 AC 49 ms
4,648 KB
testcase_03 AC 48 ms
4,576 KB
testcase_04 AC 49 ms
4,624 KB
testcase_05 AC 49 ms
4,608 KB
testcase_06 AC 48 ms
4,640 KB
testcase_07 AC 48 ms
4,624 KB
testcase_08 AC 49 ms
4,692 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> y, sy;

i64 f(i64 l, i64 r) {
  i64 m = l + (r - l) / 2;
  return sy[r] - sy[m] - (r - m) * y[m] - (sy[m] - sy[l] - (m - l) * y[m]); 
}

int main() {
  cin >> n;
  read_n(y, n);
  sort(begin(y), end(y));
  init_n(sy, n + 2);
  for (i64 i = 1; i <= n; ++i) sy[i] = sy[i - 1] + y[i - 1];
  
  i64 ans = 1ll << 50;
  bool b = false;
  for (i64 i = 1; i < n; ++i) {
    if (y[i / 2] != y[i + (n - i) / 2]) {
      ans = min(ans, f(0, i) + f(i, n));
      b = true;
    }
  }

  if (!b) ans = 1;
  cout << ans << '\n';
  return 0;
}

0