結果

問題 No.178 美しいWhitespace (1)
ユーザー darknightdarknight
提出日時 2016-11-17 20:34:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 74,364 KB
実行使用メモリ 56,976 KB
最終ジャッジ日時 2023-08-17 08:09:56
合計ジャッジ時間 8,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,824 KB
testcase_01 AC 119 ms
55,476 KB
testcase_02 AC 118 ms
55,844 KB
testcase_03 AC 119 ms
55,820 KB
testcase_04 AC 182 ms
56,432 KB
testcase_05 AC 180 ms
56,440 KB
testcase_06 AC 179 ms
56,652 KB
testcase_07 AC 178 ms
56,536 KB
testcase_08 AC 178 ms
56,428 KB
testcase_09 AC 176 ms
56,392 KB
testcase_10 AC 177 ms
56,872 KB
testcase_11 AC 181 ms
56,380 KB
testcase_12 AC 184 ms
56,532 KB
testcase_13 AC 185 ms
56,776 KB
testcase_14 AC 182 ms
56,508 KB
testcase_15 AC 185 ms
56,672 KB
testcase_16 AC 185 ms
56,376 KB
testcase_17 AC 184 ms
56,592 KB
testcase_18 AC 182 ms
56,476 KB
testcase_19 AC 185 ms
56,372 KB
testcase_20 AC 192 ms
56,632 KB
testcase_21 AC 190 ms
56,364 KB
testcase_22 AC 180 ms
56,976 KB
testcase_23 AC 185 ms
56,692 KB
testcase_24 AC 187 ms
56,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
public class Main {
	public static void main(String[] args) {
 
	Scanner sc  = new Scanner(System.in);
        
    int cnt = 0;
    int g = 0, k = 0 ;
    
    int N = Integer.parseInt(sc.next());
    
    Long[] a = new Long[N]; 
    Long[] b = new Long[N]; 
    Long[] sum = new Long[N+1]; 

    while(true){
        a[cnt] = Long.parseLong(sc.next());
        b[cnt] = Long.parseLong(sc.next());
        cnt++;
        if(cnt==N)break;
    }
    
    sum[0] = (long)0;
    for( int i = 0; i < N ; i++ ){
      
        if(a[i]%2==1) g++;
        else k++;
        sum[i+1] = a[i] + ( 4 * b[i] );

    }
    
    Arrays.sort( sum );
    Long max = sum[N];
    long d = 0;
    
    for( int i = 1; i < N ; i++ ){
         d += ( max - sum[i] ) / 2 ;
    }
    
   
    if(g>0 && k>0) System.out.print( -1 );
    else         System.out.print(  d );
        System.out.println();
        
	}
}
0