結果

問題 No.837 Noelちゃんと星々2
ユーザー pekempeypekempey
提出日時 2019-06-14 21:34:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 169,652 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-09-02 07:17:56
合計ジャッジ時間 3,349 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[0] == a[n - 1]) {
    cout << 1 << '\n';
    return 0;
  }
  vector<ll> sum(n + 1);
  rep(i, n) sum[i + 1] = sum[i] + a[i];
  ll ans = 1e18;
  for (int i = 1; i < n; i++) {
    int x = i / 2;
    int y = (n - i) / 2 + i;
    ll cost = 0;
    cost += a[x]*x - (sum[x] - sum[0]);
    cost += (sum[i] - sum[x]) - a[x]*(i-x);
    cost += a[y]*(y-i) - (sum[y] - sum[i]);
    cost += (sum[n] - sum[y]) - a[y]*(n-y);
    ans = min(ans, cost);
  }
  cout << ans << '\n';
}
0