結果

問題 No.349 干支の置き物
ユーザー YamaKasa
提出日時 2018-05-21 17:23:49
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 41,360 KB
最終ジャッジ日時 2024-06-28 15:01:45
合計ジャッジ時間 7,133 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String []A = new String[N];
		for(int i = 0; i < N; i++) {
			A[i] = scan.next();
		}
		scan.close();
		Arrays.sort(A);
		int cnt = 1;
		int max = 0;
		for(int i = 0; i < N - 1; i++) {
			if(A[i].equals(A[i + 1])) {
				cnt ++;
				if(max < cnt) {
					max = cnt;
				}
			}else {
				cnt = 1;
			}
		}
		int k = N - max;
		if(k >= max - 1) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}
0