結果

問題 No.178 美しいWhitespace (1)
ユーザー tsunabittsunabit
提出日時 2019-05-19 23:41:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 3,715 ms
コンパイル使用メモリ 76,308 KB
実行使用メモリ 60,168 KB
最終ジャッジ日時 2023-10-17 08:02:27
合計ジャッジ時間 9,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,388 KB
testcase_01 AC 136 ms
57,560 KB
testcase_02 AC 134 ms
57,560 KB
testcase_03 AC 134 ms
57,640 KB
testcase_04 AC 215 ms
59,924 KB
testcase_05 AC 217 ms
59,716 KB
testcase_06 AC 217 ms
59,968 KB
testcase_07 AC 215 ms
59,720 KB
testcase_08 AC 216 ms
59,804 KB
testcase_09 AC 215 ms
60,004 KB
testcase_10 AC 216 ms
59,836 KB
testcase_11 AC 215 ms
59,972 KB
testcase_12 AC 211 ms
59,896 KB
testcase_13 AC 215 ms
60,120 KB
testcase_14 AC 214 ms
59,892 KB
testcase_15 AC 222 ms
59,892 KB
testcase_16 AC 220 ms
59,856 KB
testcase_17 AC 220 ms
57,808 KB
testcase_18 AC 210 ms
59,868 KB
testcase_19 AC 222 ms
59,888 KB
testcase_20 AC 223 ms
59,928 KB
testcase_21 AC 219 ms
60,040 KB
testcase_22 AC 212 ms
60,168 KB
testcase_23 AC 218 ms
59,608 KB
testcase_24 AC 219 ms
59,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;

public class No178 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        ArrayList<Long> l = new ArrayList<Long>();
        
        // 𝑎+4𝑏+2𝑐
        for(int i = 0; i < n; i++) {
            // a + 4b + 2c
        	Long temp = s.nextLong() + (4 * s.nextLong());
        	l.add(temp);
        }
        Collections.sort(l, Collections.reverseOrder());
        long o = 0;
        for(Long v : l) {
        	if((l.get(0) - v) % 2 != 0) {
        		System.out.println(-1);
        		return;
        	}
        	o += l.get(0) - v;
        }
        if(o % 2 == 0) {
        	System.out.println(o / 2);
        }else {
        	System.out.println(-1);
        }
    }
}
0