結果

問題 No.349 干支の置き物
ユーザー samplelpmassamplelpmas
提出日時 2016-12-27 18:52:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 2,380 ms
コンパイル使用メモリ 75,040 KB
実行使用メモリ 54,400 KB
最終ジャッジ日時 2024-12-15 04:13:44
合計ジャッジ時間 7,770 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        Map<String, Integer> zodiac = new HashMap<String, Integer>();

        for (int i = 0; i < N; i ++) {

            String animal = sc.next();

            if (zodiac.containsKey(animal)) {
                zodiac.put(animal , zodiac.get(animal) + 1);
            } else {
                zodiac.put(animal, 1);
            }

        }

        int animalMax = 0;

        for (int numAnimal : zodiac.values()) {
            animalMax = Math.max(animalMax, numAnimal);
        }

        if (animalMax - 1  <= N - animalMax) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }

}
0