結果

問題 No.609 Noelちゃんと星々
ユーザー YamaKasaYamaKasa
提出日時 2018-09-28 13:25:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 625 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 74,800 KB
実行使用メモリ 60,860 KB
最終ジャッジ日時 2024-04-20 09:23:20
合計ジャッジ時間 19,078 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 635 ms
59,636 KB
testcase_01 AC 526 ms
59,952 KB
testcase_02 AC 433 ms
59,168 KB
testcase_03 AC 512 ms
59,444 KB
testcase_04 AC 348 ms
58,928 KB
testcase_05 AC 722 ms
59,552 KB
testcase_06 AC 665 ms
59,476 KB
testcase_07 AC 569 ms
59,332 KB
testcase_08 AC 290 ms
58,864 KB
testcase_09 AC 462 ms
59,448 KB
testcase_10 AC 621 ms
59,188 KB
testcase_11 AC 581 ms
59,356 KB
testcase_12 AC 659 ms
59,540 KB
testcase_13 AC 334 ms
58,828 KB
testcase_14 AC 248 ms
58,172 KB
testcase_15 AC 702 ms
60,004 KB
testcase_16 AC 732 ms
59,636 KB
testcase_17 AC 640 ms
59,616 KB
testcase_18 AC 461 ms
59,360 KB
testcase_19 AC 729 ms
60,192 KB
testcase_20 AC 733 ms
60,488 KB
testcase_21 AC 732 ms
59,492 KB
testcase_22 AC 695 ms
60,860 KB
testcase_23 AC 735 ms
59,616 KB
testcase_24 AC 735 ms
59,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]Y = new int[N];
		for(int i = 0; i < N; i++) {
			Y[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(Y);
		if(N % 2 == 0) {
			int t = (Y[N / 2] + Y[N /2 - 1]) / 2;
			long ans = 0;
			for(int i = 0; i < N; i++) {
				ans += Math.abs(t - Y[i]);
			}
			System.out.println(ans);
		}else {
			long ans = 0;
			int t = Y[N / 2];
			for(int i = 0; i < N; i++) {
				ans += Math.abs(t - Y[i]);
			}
			System.out.println(ans);
		}
	}
}
0