結果

問題 No.349 干支の置き物
ユーザー takeya_okino
提出日時 2017-06-20 00:06:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 77,064 KB
実行使用メモリ 54,372 KB
最終ジャッジ日時 2024-10-02 07:58:49
合計ジャッジ時間 7,931 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    for(int i = 0; i < N; i++) {
      String s = sc.next();
      if(map.containsKey(s)) {
        map.put(s, map.get(s) + 1);
      } else {
        map.put(s, 1);
      }
    }
    ArrayList<Integer> list = new ArrayList<Integer>();
    for(String s : map.keySet()) {
      list.add(map.get(s));
    }
    Collections.sort(list);
    int max = list.get(list.size() - 1);
    String ans = "NO";
    int sum = 0;
    for(int i = 0; i < list.size() - 1; i++) {
      sum += list.get(i);
    }
    if(sum >= max - 1) ans = "YES";
    System.out.println(ans);
  }
}
0