結果

問題 No.609 Noelちゃんと星々
ユーザー GBGB
提出日時 2018-12-20 11:08:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 79,512 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 00:27:27
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
4,348 KB
testcase_01 AC 21 ms
4,348 KB
testcase_02 AC 15 ms
4,348 KB
testcase_03 AC 20 ms
4,348 KB
testcase_04 AC 10 ms
4,348 KB
testcase_05 AC 49 ms
4,348 KB
testcase_06 AC 43 ms
4,348 KB
testcase_07 AC 26 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 31 ms
4,348 KB
testcase_11 AC 30 ms
4,348 KB
testcase_12 AC 38 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 45 ms
4,348 KB
testcase_16 AC 52 ms
4,348 KB
testcase_17 AC 41 ms
4,348 KB
testcase_18 AC 15 ms
4,348 KB
testcase_19 AC 43 ms
4,348 KB
testcase_20 AC 53 ms
4,348 KB
testcase_21 AC 53 ms
4,348 KB
testcase_22 AC 53 ms
4,348 KB
testcase_23 AC 53 ms
4,348 KB
testcase_24 AC 53 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;

typedef long long ll;

int main() {

	ll mid = 0;
	ll n = 0;
	vector < ll > data;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int buff;
		cin >> buff;
		data.push_back(buff);
	}

	sort(data.begin(),data.end());
	mid = (data.size() - 1) / 2;
	ll target = data[mid];
	ll distance = 0;
	for (int i : data) {
		if (i != data[mid]) {
			distance += abs(i-data[mid]);
		}
	}

	cout << distance << endl;

	return 0;
}
0