結果

問題 No.178 美しいWhitespace (1)
ユーザー spaciaspacia
提出日時 2015-12-29 17:33:23
言語 Java19
(openjdk 21)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 77,860 KB
実行使用メモリ 54,788 KB
最終ジャッジ日時 2023-10-19 12:22:23
合計ジャッジ時間 4,944 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,560 KB
testcase_01 AC 51 ms
53,564 KB
testcase_02 AC 50 ms
53,564 KB
testcase_03 AC 52 ms
53,568 KB
testcase_04 AC 87 ms
54,716 KB
testcase_05 AC 89 ms
54,448 KB
testcase_06 AC 89 ms
54,536 KB
testcase_07 AC 53 ms
53,560 KB
testcase_08 AC 85 ms
54,524 KB
testcase_09 AC 89 ms
54,448 KB
testcase_10 AC 88 ms
54,440 KB
testcase_11 AC 50 ms
53,568 KB
testcase_12 AC 51 ms
52,568 KB
testcase_13 AC 85 ms
54,440 KB
testcase_14 AC 86 ms
54,788 KB
testcase_15 AC 83 ms
54,672 KB
testcase_16 AC 94 ms
54,444 KB
testcase_17 AC 89 ms
54,716 KB
testcase_18 AC 52 ms
52,596 KB
testcase_19 AC 76 ms
54,788 KB
testcase_20 AC 51 ms
52,568 KB
testcase_21 AC 88 ms
54,440 KB
testcase_22 AC 79 ms
54,460 KB
testcase_23 AC 78 ms
54,524 KB
testcase_24 AC 87 ms
54,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main178 {
	
	public static void out (Object out) {
		System.out.println(out);
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int[] nums = new int[n];
		String[] line = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		nums[0] = a + Integer.parseInt(line[1]) * 4;
		int max = nums[0];
		
		boolean isImpossible = false;
		for (int i = 1; i < n; i++) {
			line = br.readLine().split(" ");
			int a2 = Integer.parseInt(line[0]);
			if (a % 2 != a2 % 2) {
				isImpossible = true;
				break;
			}
			nums[i] = a2 + Integer.parseInt(line[1]) * 4;
			max = Math.max(max , nums[i]);
		}
		//out("max = " + max);
		long ans = 0;
		for (int m : nums) ans += (max - m);
		
		out(isImpossible ? -1 : ans / 2);
		
	}
}
0