結果

問題 No.349 干支の置き物
ユーザー jp_ste
提出日時 2016-05-05 15:56:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 4,005 ms
コンパイル使用メモリ 77,012 KB
実行使用メモリ 41,404 KB
最終ジャッジ日時 2024-11-17 07:31:43
合計ジャッジ時間 9,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main2 {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            int N = scan.nextInt();
            HashMap<String, Integer> map = new HashMap<>();
            for(int i=0; i<N; i++) {
                String key = scan.next();
                Integer value = map.get(key);
                if(value == null) {
                    map.put(key, 1);
                } else {
                    map.replace(key, value+1);
                }                
            }
            
            int max = 0;
            for(Entry<String, Integer> e : map.entrySet()) {
                max = Math.max(max, e.getValue());
            }
            
            if((N+1)/2 >= max) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}
0