結果
| 問題 |
No.349 干支の置き物
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-12 16:01:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 2,635 bytes |
| コンパイル時間 | 3,802 ms |
| コンパイル使用メモリ | 78,136 KB |
| 実行使用メモリ | 52,376 KB |
| 最終ジャッジ日時 | 2024-09-24 16:45:52 |
| 合計ジャッジ時間 | 6,518 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
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);
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;
}
}