結果

問題 No.609 Noelちゃんと星々
ユーザー lyozlyoz
提出日時 2017-12-09 00:07:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 2,053 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 202,200 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 23:13:35
合計ジャッジ時間 3,634 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		sort(all(a));
		ll res=0;
		rep(i,n) res+=abs(a[i]-a[n/2]);
		cout<<res<<endl;
	}
}
0