結果

問題 No.178 美しいWhitespace (1)
ユーザー yagi2
提出日時 2017-04-24 12:24:42
言語 Java
(openjdk 23)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 89,908 KB
実行使用メモリ 57,000 KB
最終ジャッジ日時 2024-09-13 11:48:46
合計ジャッジ時間 8,510 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());
        List<BigInteger> width = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            width.add(new BigInteger(sc.next()).add(new BigInteger(sc.next()).multiply(new BigInteger("4"))));
        }

        width.sort((o1, o2) -> {
            if (o1.compareTo(o2) == 1) return -1;
            if (o1.compareTo(o2) == -1) return 1;
            return 0;
        });
        BigInteger max = width.get(0);

        boolean flag = true;
        BigInteger cnt = BigInteger.ZERO;
        for (int i = 1; i < N; i++) {
            if (width.get(i).compareTo(max) == 0) continue;
            if (max.subtract(width.get(i)).mod(new BigInteger("2")).compareTo(BigInteger.ZERO) == 0) {
                cnt = cnt.add(max.subtract(width.get(i)).divide(new BigInteger("2")));
            } else {
                flag = false;
                break;
            }
        }
        System.out.println((flag)? cnt : "-1");
    }
}
0