結果

問題 No.609 Noelちゃんと星々
ユーザー かにかに
提出日時 2017-12-26 02:59:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 3,875 ms
コンパイル使用メモリ 168,200 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 20:53:42
合計ジャッジ時間 4,808 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
4,376 KB
testcase_01 AC 22 ms
4,380 KB
testcase_02 AC 15 ms
4,380 KB
testcase_03 AC 20 ms
4,380 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 52 ms
4,376 KB
testcase_06 AC 44 ms
4,376 KB
testcase_07 AC 27 ms
4,380 KB
testcase_08 AC 7 ms
4,380 KB
testcase_09 AC 18 ms
4,376 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 31 ms
4,380 KB
testcase_12 AC 39 ms
4,380 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 46 ms
4,376 KB
testcase_16 AC 53 ms
4,376 KB
testcase_17 AC 43 ms
4,376 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 45 ms
4,384 KB
testcase_20 AC 55 ms
4,384 KB
testcase_21 AC 55 ms
4,376 KB
testcase_22 AC 54 ms
4,376 KB
testcase_23 AC 54 ms
4,380 KB
testcase_24 AC 54 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;
unsigned long long str_to_int(std::string str) {
  unsigned long long ret;
  std::stringstream ss; ss << str;
  ss >> ret;
  return ret;
}

int main() {
  	int n;
  	cin >> n;
  	vector<ll> v;
  	rep(i,n){
		int a;
		cin >> a;
		v.push_back(a);
  	}
	ll left = -1e9,right = 1e9;
	rep(i,100){
		ll ml = (left*2 + right)/3,mr = (left + right*2)/3;
		ll sum1 = 0,sum2 = 0;
		rep(i,n){
			sum1 += abs(v[i]-ml);
			sum2 += abs(v[i]-mr);
		}
		if(sum1 < sum2){
			right = mr;
		}else{
			left = ml;
		}
	}
	ll mini = 1e18;
	for(int i = left;i <= right;i++){
		ll sum = 0;
		rep(j,n){
			sum += abs(v[j]-i);
		}
		mini = min(mini,sum);
	}
	P(mini);
}
0