結果

問題 No.178 美しいWhitespace (1)
ユーザー tentententen
提出日時 2020-12-07 14:17:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 86,536 KB
実行使用メモリ 60,856 KB
最終ジャッジ日時 2023-10-17 16:29:37
合計ジャッジ時間 8,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,612 KB
testcase_01 AC 124 ms
57,248 KB
testcase_02 AC 127 ms
55,792 KB
testcase_03 AC 127 ms
57,604 KB
testcase_04 AC 208 ms
60,208 KB
testcase_05 AC 208 ms
59,992 KB
testcase_06 AC 204 ms
60,364 KB
testcase_07 AC 213 ms
58,460 KB
testcase_08 AC 211 ms
59,920 KB
testcase_09 AC 208 ms
60,380 KB
testcase_10 AC 215 ms
60,644 KB
testcase_11 AC 211 ms
59,928 KB
testcase_12 AC 213 ms
60,680 KB
testcase_13 AC 214 ms
58,652 KB
testcase_14 AC 211 ms
60,856 KB
testcase_15 AC 215 ms
60,188 KB
testcase_16 AC 208 ms
59,972 KB
testcase_17 AC 208 ms
60,244 KB
testcase_18 AC 203 ms
60,392 KB
testcase_19 AC 213 ms
60,168 KB
testcase_20 AC 212 ms
60,132 KB
testcase_21 AC 214 ms
60,476 KB
testcase_22 AC 195 ms
59,996 KB
testcase_23 AC 204 ms
60,096 KB
testcase_24 AC 197 ms
60,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int value = sc.nextInt() + sc.nextInt() * 4;
            map.put(value, map.getOrDefault(value, 0) + 1);
        }
        long max = map.lastKey();
        long ans = 0;
        for (int x : map.keySet()) {
            if (max % 2 != x % 2) {
                System.out.println(-1);
                return;
            }
            ans += (max - x) / 2 * map.get(x);
        }
        System.out.println(ans);
    }
}
0