結果

問題 No.178 美しいWhitespace (1)
ユーザー uafr_cs
提出日時 2015-05-15 23:43:43
言語 Java
(openjdk 23)
結果
AC  
実行時間 222 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 76,824 KB
実行使用メモリ 43,564 KB
最終ジャッジ日時 2024-07-06 04:24:36
合計ジャッジ時間 8,470 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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