結果

問題 No.837 Noelちゃんと星々2
ユーザー tentententen
提出日時 2021-03-16 11:04:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 4,580 ms
コンパイル使用メモリ 74,036 KB
実行使用メモリ 64,372 KB
最終ジャッジ日時 2023-09-02 07:33:26
合計ジャッジ時間 9,816 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
64,372 KB
testcase_01 AC 298 ms
63,888 KB
testcase_02 AC 328 ms
64,052 KB
testcase_03 AC 291 ms
63,744 KB
testcase_04 AC 296 ms
63,376 KB
testcase_05 AC 297 ms
64,068 KB
testcase_06 AC 318 ms
64,124 KB
testcase_07 AC 281 ms
62,672 KB
testcase_08 AC 299 ms
63,736 KB
testcase_09 AC 47 ms
49,340 KB
testcase_10 AC 45 ms
49,332 KB
testcase_11 AC 45 ms
49,308 KB
testcase_12 AC 44 ms
49,556 KB
testcase_13 AC 44 ms
49,104 KB
testcase_14 AC 45 ms
49,532 KB
testcase_15 AC 45 ms
49,184 KB
testcase_16 AC 44 ms
49,352 KB
testcase_17 AC 45 ms
49,216 KB
testcase_18 AC 44 ms
49,400 KB
testcase_19 AC 45 ms
49,320 KB
testcase_20 AC 45 ms
49,208 KB
testcase_21 AC 46 ms
49,336 KB
testcase_22 AC 45 ms
49,224 KB
testcase_23 AC 45 ms
49,508 KB
testcase_24 AC 44 ms
49,328 KB
testcase_25 AC 44 ms
49,368 KB
testcase_26 AC 44 ms
49,204 KB
testcase_27 AC 44 ms
49,332 KB
testcase_28 AC 43 ms
49,456 KB
testcase_29 AC 44 ms
47,216 KB
testcase_30 AC 43 ms
49,128 KB
testcase_31 AC 43 ms
49,260 KB
testcase_32 AC 44 ms
49,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ", n);
		int[] positions = new int[n];
		for (int i = 0; i < n; i++) {
		    positions[i] = Integer.parseInt(line[i]);
		}
		Arrays.sort(positions);
		if (positions[0] == positions[n - 1]) {
		    System.out.println(1);
		    return;
		}
		long[] sums = new long[n];
		sums[0] = positions[0];
		for (int i = 1; i < n; i++) {
		    sums[i] = sums[i - 1] + positions[i];
		}
		long min = Long.MAX_VALUE;
		for (int i = 1; i < n; i++) {
		    int leftc = (i - 1) / 2;
		    long tmp = positions[leftc] * (long)(leftc + 1) - sums[leftc];
		    tmp += sums[i - 1] - sums[leftc] - positions[leftc] * (long)(i - leftc - 1);
		    int rightc = (n - 1 + i) / 2;
		    tmp += positions[rightc] *(long)(rightc - i + 1) - (sums[rightc] - sums[i - 1]);
		    tmp += sums[n - 1] - sums[rightc] - positions[rightc] * (long)(n - 1 - rightc);
		    min = Math.min(min, tmp);
		}
		System.out.println(min);
   }
   
}
0