結果

問題 No.609 Noelちゃんと星々
ユーザー dustnn0dustnn0
提出日時 2018-03-10 22:37:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 505 bytes
コンパイル時間 2,640 ms
コンパイル使用メモリ 165,956 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 18:29:25
合計ジャッジ時間 4,906 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 23 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 29 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 19 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 42 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 5 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 58 ms
5,376 KB
testcase_17 AC 45 ms
5,376 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

int N;
const ll MA=1000000000;
ll a[100000];

ll solve(ll x){
  ll res=0;
  rep(i,N) res+=abs(a[i]-x);
  return res;
}

int main(){
  cin>>N;
  rep(i,N) cin>>a[i];
  sort(a,a+N);
  int lb=-MA,ub=MA;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(solve(mid)>solve(mid+1)) lb=mid;
    else ub=mid;
  }
  cout<<solve(lb)-1<<endl;
  return 0;
}
0