結果

問題 No.609 Noelちゃんと星々
ユーザー lumc_lumc_
提出日時 2017-12-10 07:07:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,118 bytes
コンパイル時間 777 ms
コンパイル使用メモリ 93,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 07:32:01
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
4,380 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 20 ms
4,380 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 13 ms
4,380 KB
testcase_11 AC 12 ms
4,376 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 18 ms
4,380 KB
testcase_16 AC 21 ms
4,380 KB
testcase_17 AC 17 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 21 ms
4,384 KB
testcase_22 AC 21 ms
4,380 KB
testcase_23 AC 22 ms
4,384 KB
testcase_24 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
const bool DEBUG = 1;
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>
#include <stdio.h>
#include <sys/time.h>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef pair<int, PP> IPP;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<int(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=int(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define LREP(i,n) LFOR(i,0,n)
#define LRFOR(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define LRREP(i,b,a) LRFOR(i,0,n)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define REACH(i,c) RREP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define BR cout << "\n"

#define dump(x) if(DEBUG)cerr<<"[" << __LINE__ << "] "<<#x<<"="<<(x)<<"\n"
#define dump2(x,y) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
			<<" , "<<#y<<"="<<(y)<<"\n"
#define dump3(x,y,z) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
			<<" , "<<#y<<"="<<(y)<<"\n"\
			<<" , "<<#z<<"="<<(z)<<"\n"

#define SAY(x) if(DEBUG) cerr << "[" << __LINE__ << "] " << (x) << "\n"

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

ll ans;
int a[100000];

int main() {
	omajinai;
	ll n;
	cin>>n;
	REP(i, n){
		cin >> a[i];
	}

	sort(a, a+n);

	ll k;
	k=0;
	REP(i, n) k += abs((ll)a[i] - a[n/2]);
	ans = k;
	k=0;
	REP(i, n) k += abs((ll)a[i] - a[min(n-1, n/2+1)]);
	ans = min(ans, k);
	cout<<ans<<endl;
//	if(1){
//		cout << "Yes" << endl;
//	}else{
//		cout << "No" << endl;
//	}
}
0