結果

問題 No.178 美しいWhitespace (1)
ユーザー yagi2yagi2
提出日時 2017-04-24 12:17:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 972 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 78,548 KB
実行使用メモリ 59,140 KB
最終ジャッジ日時 2023-10-11 13:01:27
合計ジャッジ時間 8,426 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,836 KB
testcase_01 AC 116 ms
55,472 KB
testcase_02 AC 118 ms
56,208 KB
testcase_03 AC 119 ms
56,168 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 181 ms
56,640 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 178 ms
56,592 KB
testcase_12 AC 180 ms
56,680 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 184 ms
56,520 KB
testcase_19 WA -
testcase_20 AC 176 ms
56,196 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 182 ms
56,304 KB
testcase_24 AC 180 ms
56,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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<Long> width = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            width.add(Long.parseLong(sc.next()) + Long.parseLong(sc.next()) * 4);
        }

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

        boolean flag = true;
        int cnt = 0;
        for (int i = 1; i < N; i++) {
            if (width.get(i) == max) continue;
            if ((max - width.get(i)) % 2 == 0) {
                cnt += ((max - width.get(i)) / 2);
            } else {
                flag = false;
                break;
            }
        }
        System.out.println((flag)? cnt : "-1");
    }
}
0