結果
| 問題 | 
                            No.178 美しいWhitespace (1)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             spacia
                         | 
                    
| 提出日時 | 2015-12-29 17:33:23 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 88 ms / 2,000 ms | 
| コード長 | 934 bytes | 
| コンパイル時間 | 2,320 ms | 
| コンパイル使用メモリ | 77,852 KB | 
| 実行使用メモリ | 38,380 KB | 
| 最終ジャッジ日時 | 2024-09-19 08:25:44 | 
| 合計ジャッジ時間 | 4,864 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 21 | 
ソースコード
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);
		
	}
}
            
            
            
        
            
spacia