結果

問題 No.837 Noelちゃんと星々2
ユーザー 👑 emthrmemthrm
提出日時 2019-06-15 00:24:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 127,568 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-09-02 07:22:50
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<long long> y(n); REP(i, n) cin >> y[i];
  sort(ALL(y));
  if (y.front() == y.back()) {
    cout << 1 << '\n';
    return 0;
  }
  vector<long long> cum(n + 1, 0);
  REP(i, n) cum[i + 1] = cum[i] + y[i];
  long long ans = LINF;
  FOR(i, 1, n) {
    long long sum = 0;
    int left = (0 + i - 1) / 2;
    sum += y[left] * left - (cum[left] - cum[0]);
    sum += (cum[i] - cum[left]) - y[left] * (i - left);
    int right = (i + n - 1) / 2;
    sum += y[right] * (right - i) - (cum[right] - cum[i]);
    sum += (cum[n] - cum[right]) - y[right] * (n - right);
    ans = min(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}
0