結果

問題 No.178 美しいWhitespace (1)
ユーザー uafr_csuafr_cs
提出日時 2015-05-15 23:43:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 73,844 KB
実行使用メモリ 59,052 KB
最終ジャッジ日時 2023-09-20 08:42:19
合計ジャッジ時間 8,123 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,048 KB
testcase_01 AC 126 ms
55,836 KB
testcase_02 AC 119 ms
55,876 KB
testcase_03 AC 123 ms
56,048 KB
testcase_04 AC 195 ms
57,976 KB
testcase_05 AC 198 ms
58,144 KB
testcase_06 AC 197 ms
58,408 KB
testcase_07 AC 194 ms
57,948 KB
testcase_08 AC 198 ms
58,228 KB
testcase_09 AC 200 ms
58,536 KB
testcase_10 AC 197 ms
58,900 KB
testcase_11 AC 199 ms
58,936 KB
testcase_12 AC 193 ms
58,156 KB
testcase_13 AC 197 ms
58,296 KB
testcase_14 AC 199 ms
59,052 KB
testcase_15 AC 195 ms
58,420 KB
testcase_16 AC 198 ms
58,812 KB
testcase_17 AC 198 ms
58,080 KB
testcase_18 AC 194 ms
58,972 KB
testcase_19 AC 196 ms
58,148 KB
testcase_20 AC 196 ms
58,996 KB
testcase_21 AC 202 ms
57,948 KB
testcase_22 AC 189 ms
58,120 KB
testcase_23 AC 198 ms
58,752 KB
testcase_24 AC 196 ms
58,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		long[] array = new long[N];
		for(int i = 0; i < N; i++){
			final int a = sc.nextInt();
			final int b = sc.nextInt();
			
			array[i] = a + 4 * b;
		}
		
		boolean ok = true;
		final long fst_mod = array[0] % 2;
		for(int i = 1; i < N; i++){
			if(array[i] % 2 != fst_mod){
				ok = false;
				break;
			}
		}
		
		if(!ok){
			System.out.println(-1);
		}else{
			long max = 0;
			for(int i = 0; i < N; i++){
				max = Math.max(max, array[i]);
			}
			
			long count = 0;
			for(int i = 0; i < N; i++){
				count += (max - array[i]) / 2;
			}
			
			System.out.println(count);
		}
		
	}
	
}
0