結果

問題 No.837 Noelちゃんと星々2
ユーザー 37zigen37zigen
提出日時 2019-06-15 00:11:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 77,980 KB
実行使用メモリ 63,524 KB
最終ジャッジ日時 2024-04-27 14:25:08
合計ジャッジ時間 13,410 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 125 ms
54,068 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 124 ms
53,916 KB
testcase_25 AC 125 ms
54,064 KB
testcase_26 AC 112 ms
52,952 KB
testcase_27 AC 125 ms
53,748 KB
testcase_28 AC 123 ms
54,112 KB
testcase_29 AC 113 ms
52,916 KB
testcase_30 AC 123 ms
54,204 KB
testcase_31 AC 123 ms
53,888 KB
testcase_32 AC 127 ms
54,444 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 ans = Long.MAX_VALUE / 3;
		for (int d1 = -1; d1 <= 1; ++d1) {
			for (int d2 = -1; d2 <= 1; ++d2) {
				if (n / 3 + d1 < 0 || n / 3 * 2 + d2 < 0 || n / 3 + d1 >= n || n / 3 * 2 + d2 >= n
						|| Y[n / 3 + d1] == Y[n / 3 * 2 + d2])
					continue;
				long ans_tmp = 0;
				for (int i = 0; i < n; ++i) {
					ans_tmp += Math.min(Math.abs(Y[i] - Y[n / 3 + d1]), Math.abs(Y[i] - Y[n / 3 * 2 + d2]));
				}
				ans = Math.min(ans, ans_tmp);
			}
		}
		System.out.println(ans);
	}

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