結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | htensai |
提出日時 | 2020-05-07 18:34:50 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 633 ms / 5,000 ms |
コード長 | 1,207 bytes |
コンパイル時間 | 2,106 ms |
コンパイル使用メモリ | 76,492 KB |
実行使用メモリ | 62,476 KB |
最終ジャッジ日時 | 2023-09-16 08:02:54 |
合計ジャッジ時間 | 5,519 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 633 ms
60,564 KB |
testcase_01 | AC | 606 ms
60,492 KB |
testcase_02 | AC | 484 ms
60,572 KB |
testcase_03 | AC | 608 ms
62,476 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int j = 0; j < t; j++) { int n = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (map.containsKey(x)) { map.put(x, map.get(x) + 1); } else { map.put(x, 1); } } int[] counts = new int[n + 1]; for (int x : map.values()) { counts[x]++; } int left = 0; int right = n / 3 + 1; while (right - left > 1) { int m = (left + right) / 2; if (check(m, counts)) { left = m; } else { right = m; } } sb.append(left).append("\n"); } System.out.print(sb); } static boolean check(int target, int[] counts) { int count = 0; for (int i = 1; i < counts.length; i++) { count += Math.min(target, i) * counts[i]; if (count >= target * 3) { return true; } } return false; } }