結果

問題 No.609 Noelちゃんと星々
ユーザー utouto97utouto97
提出日時 2019-03-30 20:44:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 157,800 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 12:16:27
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/
int n, a[100000];

int f(int x)
{
  int ret = 0;
  rep(i, 0, n) ret += abs(a[i]-x);
  return ret;
}

signed main()
{
  cin >> n;
  rep(i, 0, n) cin >> a[i];

  int l = -1e9, r = 1e9;
  while(r-l > 1){
    if(f(l) < f(r)) r = (l+r)/2;
    else l = (l+r)/2;
  }

  if(f(l) < f(r)) cout << f(l) << endl;
  else cout << f(r) << endl;

  return 0;
}
0