結果

問題 No.178 美しいWhitespace (1)
ユーザー yagi2yagi2
提出日時 2017-04-24 12:24:42
言語 Java19
(openjdk 21)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 83,300 KB
実行使用メモリ 61,140 KB
最終ジャッジ日時 2023-10-11 13:02:25
合計ジャッジ時間 8,366 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,624 KB
testcase_01 AC 120 ms
56,336 KB
testcase_02 AC 122 ms
55,632 KB
testcase_03 AC 120 ms
56,028 KB
testcase_04 AC 207 ms
58,884 KB
testcase_05 AC 203 ms
58,944 KB
testcase_06 AC 204 ms
58,804 KB
testcase_07 AC 197 ms
57,000 KB
testcase_08 AC 193 ms
59,076 KB
testcase_09 AC 201 ms
61,140 KB
testcase_10 AC 202 ms
59,044 KB
testcase_11 AC 191 ms
56,480 KB
testcase_12 AC 197 ms
57,424 KB
testcase_13 AC 205 ms
59,196 KB
testcase_14 AC 203 ms
58,564 KB
testcase_15 AC 206 ms
59,168 KB
testcase_16 AC 211 ms
59,176 KB
testcase_17 AC 213 ms
59,000 KB
testcase_18 AC 196 ms
54,712 KB
testcase_19 AC 209 ms
59,576 KB
testcase_20 AC 192 ms
56,700 KB
testcase_21 AC 202 ms
59,444 KB
testcase_22 AC 191 ms
59,288 KB
testcase_23 AC 191 ms
56,780 KB
testcase_24 AC 194 ms
54,828 KB
権限があれば一括ダウンロードができます

ソースコード

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