結果

問題 No.609 Noelちゃんと星々
ユーザー te-shte-sh
提出日時 2018-01-10 13:45:39
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 466 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 95,408 KB
実行使用メモリ 6,504 KB
最終ジャッジ日時 2023-09-03 18:02:37
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
4,424 KB
testcase_01 AC 14 ms
4,376 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 32 ms
4,984 KB
testcase_06 AC 28 ms
6,504 KB
testcase_07 AC 17 ms
5,168 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 20 ms
4,376 KB
testcase_12 AC 25 ms
4,376 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 29 ms
5,976 KB
testcase_16 AC 33 ms
6,308 KB
testcase_17 AC 26 ms
4,400 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 28 ms
5,904 KB
testcase_20 AC 34 ms
5,068 KB
testcase_21 AC 34 ms
5,060 KB
testcase_22 AC 34 ms
5,044 KB
testcase_23 AC 34 ms
5,836 KB
testcase_24 AC 33 ms
5,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions

void main()
{
  auto n = read1!int;
  auto y = readArray!int(n);
  y.sort();

  auto m = n&1 ? y[n/2] : (y[n/2-1]+y[n/2])/2;
  auto ans = 0L;
  foreach (yi; y) ans += (yi-m).abs;

  writeln(ans);
}

T read1(T)(){return readln.chomp.to!T;}
T[] readArray(T)(size_t n){auto a=new T[](n),r=readln.splitter;foreach(ref ai;a){ai=r.front.to!T;r.popFront;}return a;}
0