結果

問題 No.837 Noelちゃんと星々2
ユーザー 37zigen37zigen
提出日時 2019-06-15 02:13:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 641 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 3,983 ms
コンパイル使用メモリ 74,908 KB
実行使用メモリ 62,648 KB
最終ジャッジ日時 2023-09-02 07:23:49
合計ジャッジ時間 12,923 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 612 ms
62,400 KB
testcase_01 AC 639 ms
62,448 KB
testcase_02 AC 600 ms
62,372 KB
testcase_03 AC 616 ms
62,412 KB
testcase_04 AC 608 ms
62,120 KB
testcase_05 AC 641 ms
62,464 KB
testcase_06 AC 634 ms
62,324 KB
testcase_07 AC 600 ms
62,616 KB
testcase_08 AC 625 ms
62,648 KB
testcase_09 AC 139 ms
55,992 KB
testcase_10 AC 136 ms
55,764 KB
testcase_11 AC 137 ms
55,492 KB
testcase_12 AC 121 ms
55,764 KB
testcase_13 AC 120 ms
55,944 KB
testcase_14 AC 126 ms
55,744 KB
testcase_15 AC 127 ms
56,044 KB
testcase_16 AC 118 ms
55,920 KB
testcase_17 AC 125 ms
55,916 KB
testcase_18 AC 119 ms
55,648 KB
testcase_19 AC 125 ms
55,892 KB
testcase_20 AC 129 ms
55,920 KB
testcase_21 AC 129 ms
56,024 KB
testcase_22 AC 128 ms
55,920 KB
testcase_23 AC 126 ms
55,924 KB
testcase_24 AC 118 ms
56,388 KB
testcase_25 AC 121 ms
55,864 KB
testcase_26 AC 127 ms
55,928 KB
testcase_27 AC 119 ms
56,112 KB
testcase_28 AC 119 ms
55,796 KB
testcase_29 AC 119 ms
55,756 KB
testcase_30 AC 119 ms
55,444 KB
testcase_31 AC 118 ms
55,608 KB
testcase_32 AC 120 ms
55,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] Y = new long[n];
		boolean f = true;
		for (int i = 0; i < n; ++i) {
			Y[i] = sc.nextLong();
			f &= Y[i] == Y[0];
		}
		if (f) {
			System.out.println(1);
			return;
		}
		Arrays.sort(Y);
		long[] sum = new long[n];
		for (int i = 0; i < n; ++i) {
			sum[i] = (i > 0 ? sum[i - 1] : 0) + Y[i];
		}
		long ans = Long.MAX_VALUE / 3;
		for (int i = 1; i  < n; ++i) {
			// [0, i)
			// [i, n)
			long cur = 0;

			int m = i / 2;
			cur += Y[m] * (m + 1) - sum[m];
			cur += (sum[i - 1] - sum[m]) - Y[m] * (i - 1 - m);

			m = (n - i) / 2;
			cur += Y[i + m] * (m + 1) - (sum[i + m] - sum[i - 1]);
			cur += (sum[n - 1] - sum[i + m]) - Y[i + m] * ((n - 1) - (i + m));


			ans = Math.min(ans, cur);
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0