結果

問題 No.349 干支の置き物
ユーザー nihi9119nihi9119
提出日時 2017-06-12 16:00:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,640 bytes
コンパイル時間 6,324 ms
コンパイル使用メモリ 80,456 KB
実行使用メモリ 53,496 KB
最終ジャッジ日時 2023-10-24 21:33:24
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
53,476 KB
testcase_01 AC 57 ms
53,484 KB
testcase_02 AC 57 ms
53,496 KB
testcase_03 AC 57 ms
53,476 KB
testcase_04 AC 57 ms
52,616 KB
testcase_05 AC 56 ms
53,492 KB
testcase_06 AC 57 ms
53,476 KB
testcase_07 AC 59 ms
53,480 KB
testcase_08 AC 56 ms
53,480 KB
testcase_09 AC 57 ms
53,484 KB
testcase_10 AC 55 ms
52,592 KB
testcase_11 AC 56 ms
53,480 KB
testcase_12 AC 58 ms
53,476 KB
testcase_13 AC 55 ms
53,484 KB
testcase_14 AC 57 ms
53,476 KB
testcase_15 AC 55 ms
53,480 KB
testcase_16 AC 55 ms
53,424 KB
testcase_17 AC 56 ms
53,480 KB
testcase_18 AC 55 ms
53,484 KB
testcase_19 AC 56 ms
51,536 KB
testcase_20 AC 57 ms
52,612 KB
testcase_21 AC 56 ms
53,480 KB
testcase_22 AC 57 ms
52,644 KB
testcase_23 AC 57 ms
53,496 KB
testcase_24 AC 55 ms
53,484 KB
testcase_25 AC 55 ms
53,496 KB
testcase_26 AC 56 ms
53,484 KB
testcase_27 AC 56 ms
53,492 KB
testcase_28 AC 55 ms
53,488 KB
testcase_29 AC 55 ms
53,480 KB
testcase_30 AC 56 ms
53,480 KB
testcase_31 AC 56 ms
53,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test7;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * No.349 干支の置き物
 * http://yukicoder.me/problems/no/349
 */

public class Question_18_0612_1 {

	final static int MIN = 2;
	final static int MAX = 50;
	static HashMap<String, Integer> etoMap = new HashMap<String, Integer>();

	public static void main(String[] args) {

		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {

			//入力
			int etoCount = Integer.parseInt(br.readLine());
			List<String> etoList = new ArrayList<String>();
			for (int i = 0; i < etoCount; i++) {
				etoList.add(br.readLine());
			}
			// 入力判定
			if (NumJudg(etoCount, MIN, MAX)) {

				// 半分以上になったら隣通し並べられてしまう
				int overCount = (int) Math.floor(etoCount / 2) + 1;
				if (etoCount % 2 != 0) {
					overCount++;
				}

				//結果取得
				boolean overFlg = etoCheck(etoList, overCount);

				// 結果
				if (overFlg) {
					System.out.println("NO");
				} else {
					System.out.println("YES");
				}

			} else {
				System.out.println("入力が有効値外です");
			}

		} catch (NumberFormatException e){

		} catch (IOException e) {

		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}

	}

	/**
	 * 干支の名前を数をチェックし、数がoverCountを超えたらfalseを返す
	 * @param etoList 干支の名前リスト
	 * @param overCount 超えてはいけない数
	 * @return overCountを超えたかどうか
	 */
	private static boolean etoCheck(List<String> etoList, int overCount) {
		//Map登録しながら確認
		boolean overFlg = false;
		int count;
		for (String etoName : etoList) {
			if (etoMap.containsKey(etoName)) {
				// Map登録済み(カウントを増やす)
				count = etoMap.get(etoName) + 1;
			} else {
				// Mapに未登録(登録する)
				count = 1;
			}
			if (count >= overCount) {
				overFlg = true;
				break;
			}
			etoMap.put(etoName, count);
		}
		return overFlg;
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean NumJudg(int input, int min, int max) {
		Boolean result = false;
		if (min <= input && input <= max) {
			result = true;
		}
		return result;
	}

}
0