結果

問題 No.609 Noelちゃんと星々
ユーザー motimoti
提出日時 2018-05-24 00:31:59
言語 Perl
(5.38.2)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 318 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 18,496 KB
最終ジャッジ日時 2023-09-11 02:05:03
合計ジャッジ時間 3,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,324 KB
testcase_01 AC 39 ms
9,892 KB
testcase_02 AC 27 ms
8,140 KB
testcase_03 AC 36 ms
9,428 KB
testcase_04 AC 20 ms
7,072 KB
testcase_05 AC 117 ms
17,476 KB
testcase_06 AC 88 ms
15,696 KB
testcase_07 AC 48 ms
11,332 KB
testcase_08 AC 13 ms
6,200 KB
testcase_09 AC 31 ms
8,680 KB
testcase_10 AC 63 ms
13,088 KB
testcase_11 AC 59 ms
12,472 KB
testcase_12 AC 72 ms
14,224 KB
testcase_13 AC 15 ms
6,672 KB
testcase_14 AC 9 ms
5,720 KB
testcase_15 AC 93 ms
16,028 KB
testcase_16 AC 116 ms
17,976 KB
testcase_17 AC 82 ms
15,392 KB
testcase_18 AC 27 ms
8,380 KB
testcase_19 AC 91 ms
15,788 KB
testcase_20 AC 129 ms
18,448 KB
testcase_21 AC 127 ms
18,312 KB
testcase_22 AC 126 ms
18,496 KB
testcase_23 AC 114 ms
18,392 KB
testcase_24 AC 118 ms
18,196 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/env perl

use strict;
use warnings;

my $n = <>;
my @ys = split / /, <>;
@ys = sort { $a <=> $b } @ys;
my $target;
if ($n % 2) {
  $target = $ys[$n / 2];
} else {
  my $p = int($n / 2);
  $target = ($ys[$p - 1] + $ys[$p]) / 2;
}
my $ans = 0;
for my $e (@ys) {
  $ans += abs($e - $target);
}
print "$ans\n";
0