結果

問題 No.349 干支の置き物
ユーザー htensaihtensai
提出日時 2019-11-21 16:45:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 3,287 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 41,740 KB
最終ジャッジ日時 2024-04-18 12:08:31
合計ジャッジ時間 7,401 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
40,904 KB
testcase_01 AC 129 ms
41,356 KB
testcase_02 AC 128 ms
41,024 KB
testcase_03 AC 124 ms
41,072 KB
testcase_04 AC 126 ms
41,740 KB
testcase_05 AC 128 ms
41,532 KB
testcase_06 AC 132 ms
41,012 KB
testcase_07 AC 128 ms
41,180 KB
testcase_08 AC 125 ms
41,720 KB
testcase_09 AC 120 ms
41,312 KB
testcase_10 AC 120 ms
39,992 KB
testcase_11 AC 130 ms
41,444 KB
testcase_12 AC 121 ms
40,484 KB
testcase_13 AC 129 ms
41,328 KB
testcase_14 AC 131 ms
41,152 KB
testcase_15 AC 131 ms
41,320 KB
testcase_16 AC 128 ms
41,196 KB
testcase_17 AC 123 ms
41,256 KB
testcase_18 AC 121 ms
41,472 KB
testcase_19 AC 123 ms
41,340 KB
testcase_20 AC 121 ms
39,808 KB
testcase_21 AC 123 ms
41,108 KB
testcase_22 AC 130 ms
41,340 KB
testcase_23 AC 120 ms
40,148 KB
testcase_24 AC 124 ms
41,216 KB
testcase_25 AC 125 ms
41,636 KB
testcase_26 AC 123 ms
39,936 KB
testcase_27 AC 120 ms
40,024 KB
testcase_28 AC 119 ms
39,896 KB
testcase_29 AC 128 ms
41,144 KB
testcase_30 AC 132 ms
41,300 KB
testcase_31 AC 126 ms
41,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static Point[] points;
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
		    String eto = sc.next();
		    if (map.containsKey(eto)) {
		        map.put(eto, map.get(eto) + 1);
		    } else {
		        map.put(eto, 1);
		    }
		}
		int max = 0;
		for (int x : map.values()) {
		    max = Math.max(max, x);
		}
		if ((n + 1) / 2 >= max) {
		    System.out.println("YES");
		} else {
		    System.out.println("NO");
		}
	}
	
	static int getCount(int idx, ArrayList<Integer> list, boolean[] used, int score) {
	    if (idx >= points.length) {
	        return score;
	    }
	    int ans = getCount(idx + 1, list, used, score);
	    Point p = points[idx];
	    if (used[p.left]) {
	        if (used[p.right]) {
	            boolean flag = false;
	            for (int x : list) {
	                if (x == p.left) {
	                    flag = true;
	                } else if (x == p.right) {
	                    if (flag) {
	                        ans += p.value;
	                    }
	                    break;
	                }
	            }
	        } else {
	            boolean flag = false;
	            for (int i = 0; i <= list.size(); i++) {
	                if (flag) {
	                    used[p.right] = true;
	                    list.add(i, p.right);
	                    ans = Math.max(ans, getCount(idx + 1, list, used, score + p.value));
	                    used[p.right] = false;
	                    list.remove(i);
	                } else {
	                    if (list.get(i) == p.left) {
	                        flag = true;
	                    }
	                }
	            }
	        }
	    } else {
	        if (used[p.right]) {
	            boolean flag = false;
	            for (int i = list.size() - 1; i >= 0; i--) {
	                if (flag) {
	                    used[p.left] = true;
	                    list.add(i, p.left);
	                    ans = Math.max(ans, getCount(idx + 1, list, used, score + p.value));
	                    used[p.left] = false;
	                    list.remove(i);
	                } else {
	                    if (list.get(i) == p.right) {
	                        flag = true;
	                        i--;
	                    }
	                }
	            }
	        } else {
	            for (int i = 0; i <= list.size(); i++) {
                    used[p.left] = true;
                    list.add(i, p.left);
                    for (int j = i + 1; j <= list.size(); j++) {
 	                    used[p.right] = true;
	                    list.add(j, p.right);
	                    ans = Math.max(ans, getCount(idx + 1, list, used, score + p.value));
	                    used[p.right] = false;
	                    list.remove(j);
                   }
                    used[p.left] = false;
                    list.remove(i);
	            }
	        }
	    }
	    return ans;
	}
	
	static class Point {
	    int left;
	    int right;
	    int value;
	    
	    public Point(int left, int right, int value) {
	        this.left = left;
	        this.right = right;
	        this.value = value;
	    }
	}
}
0