結果

問題 No.837 Noelちゃんと星々2
ユーザー 37zigen37zigen
提出日時 2019-06-15 00:14:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,009 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 69,568 KB
最終ジャッジ日時 2024-04-27 14:27:40
合計ジャッジ時間 18,755 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 147 ms
54,128 KB
testcase_10 AC 139 ms
54,232 KB
testcase_11 AC 134 ms
53,976 KB
testcase_12 AC 121 ms
52,788 KB
testcase_13 AC 135 ms
54,080 KB
testcase_14 AC 141 ms
54,316 KB
testcase_15 AC 144 ms
54,020 KB
testcase_16 AC 132 ms
53,912 KB
testcase_17 AC 142 ms
54,128 KB
testcase_18 AC 132 ms
53,956 KB
testcase_19 AC 141 ms
54,108 KB
testcase_20 AC 127 ms
52,784 KB
testcase_21 AC 144 ms
54,160 KB
testcase_22 AC 145 ms
54,408 KB
testcase_23 AC 125 ms
52,696 KB
testcase_24 AC 126 ms
54,044 KB
testcase_25 AC 130 ms
54,060 KB
testcase_26 AC 128 ms
53,976 KB
testcase_27 AC 119 ms
53,360 KB
testcase_28 AC 126 ms
54,084 KB
testcase_29 AC 134 ms
54,148 KB
testcase_30 AC 129 ms
54,176 KB
testcase_31 AC 127 ms
53,896 KB
testcase_32 AC 126 ms
54,272 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 = -10; d1 <= 10; ++d1) {
			for (int d2 = -10; d2 <= 10; ++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