結果

問題 No.178 美しいWhitespace (1)
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-12 00:05:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 2,148 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 59,232 KB
最終ジャッジ日時 2023-08-13 17:42:15
合計ジャッジ時間 8,306 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,328 KB
testcase_01 AC 124 ms
55,760 KB
testcase_02 AC 125 ms
55,892 KB
testcase_03 AC 125 ms
56,232 KB
testcase_04 AC 199 ms
58,852 KB
testcase_05 AC 200 ms
58,980 KB
testcase_06 AC 202 ms
58,712 KB
testcase_07 AC 200 ms
58,188 KB
testcase_08 AC 202 ms
58,816 KB
testcase_09 AC 201 ms
58,660 KB
testcase_10 AC 198 ms
58,452 KB
testcase_11 AC 204 ms
58,668 KB
testcase_12 AC 199 ms
58,060 KB
testcase_13 AC 200 ms
56,708 KB
testcase_14 AC 201 ms
58,664 KB
testcase_15 AC 204 ms
58,348 KB
testcase_16 AC 201 ms
56,040 KB
testcase_17 AC 200 ms
59,232 KB
testcase_18 AC 198 ms
58,820 KB
testcase_19 AC 201 ms
59,168 KB
testcase_20 AC 195 ms
58,400 KB
testcase_21 AC 194 ms
58,432 KB
testcase_22 AC 195 ms
58,160 KB
testcase_23 AC 195 ms
58,488 KB
testcase_24 AC 198 ms
58,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] width = new int[n];
		for (int i=0; i<n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			width[i] = a + 4*b;
		}
		Arrays.sort(width);
		int max = width[n-1];
		long num = 0;
		boolean possible = true;
		for (int i=0; i<n; i++) {
			int dif = max-width[i];
			if (dif%2==0) {
				num += dif/2;
			}
			else {possible = false; break;}
		}
		
		System.out.println(possible==true?num:-1);
	}
}
0