結果

問題 No.609 Noelちゃんと星々
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-06-05 17:35:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 147,004 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-12 22:26:59
合計ジャッジ時間 3,479 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
4,376 KB
testcase_01 AC 21 ms
4,380 KB
testcase_02 AC 15 ms
4,380 KB
testcase_03 AC 19 ms
4,384 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 48 ms
4,376 KB
testcase_06 AC 43 ms
4,380 KB
testcase_07 AC 26 ms
4,376 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 31 ms
4,376 KB
testcase_11 AC 30 ms
4,380 KB
testcase_12 AC 37 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 5 ms
4,388 KB
testcase_15 AC 43 ms
4,380 KB
testcase_16 AC 50 ms
4,376 KB
testcase_17 AC 40 ms
4,376 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 43 ms
4,376 KB
testcase_20 AC 52 ms
4,380 KB
testcase_21 AC 52 ms
4,380 KB
testcase_22 AC 52 ms
4,376 KB
testcase_23 AC 52 ms
4,376 KB
testcase_24 AC 51 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

i64 N;
vector<i64> X;

i64 f(i64 k){
  i64 ans = 0;
  for(i64 x : X){
    ans += abs(x - k);
  }
  return ans;
}

int main(){
  cin >> N;
  X.resize(N);
  rep(i,0,N - 1) cin >> X[i];

  i64 x0 = -1e9;
  i64 x3 = 1e9;
  while(x3 - x0 > 10){
    i64 x1 = (x0 * 2 + x3) / 3;
    i64 x2 = (x0 + x3 * 2) / 3;
    if(f(x1) < f(x2)){
      x3 = x2;
    }
    else{
      x0 = x1;
    }
  }
  i64 MIN = f(x0);
  rep(i,x0,x3){
    MIN = min(MIN,f(i));
  }
  cout << MIN << endl;
}
0