結果

問題 No.178 美しいWhitespace (1)
ユーザー tenten
提出日時 2020-12-07 14:17:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 76,600 KB
実行使用メモリ 57,652 KB
最終ジャッジ日時 2024-09-17 13:53:46
合計ジャッジ時間 7,359 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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