結果

問題 No.79 過小評価ダメ・ゼッタイ
コンテスト
ユーザー yagi2
提出日時 2017-04-25 14:37:34
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 940 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,742 ms
コンパイル使用メモリ 90,156 KB
実行使用メモリ 56,548 KB
最終ジャッジ日時 2026-03-13 00:07:03
合計ジャッジ時間 6,060 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;

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

        int N = Integer.parseInt(sc.next());

        Map<Integer, Integer> L = new HashMap<>();
        for (int i = 0 ; i < N; i++) {
            int l = Integer.parseInt(sc.next());

            if (!L.containsKey(l)) L.put(l, 0);
            L.put(l, L.get(l)+1);
        }

        List<Map.Entry<Integer, Integer>> entryList = new ArrayList<>(L.entrySet());
        entryList.sort((o1, o2) -> {
            if (o1.getValue() > o2.getValue()) return -1;
            if (o1.getValue() < o2.getValue()) return 1;

            if (Objects.equals(o1.getValue(), o2.getValue())) {
                if (o1.getKey() > o2.getKey()) return -1;
                if (o1.getKey() < o2.getKey()) return 1;
            }
            return 0;
        });

        System.out.println(entryList.get(0).getKey());
    }
}
0