結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー tentententen
提出日時 2020-11-17 20:13:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 666 ms / 5,000 ms
コード長 1,138 bytes
コンパイル時間 2,738 ms
コンパイル使用メモリ 81,936 KB
実行使用メモリ 62,832 KB
最終ジャッジ日時 2023-09-30 14:24:38
合計ジャッジ時間 5,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 627 ms
60,076 KB
testcase_01 AC 666 ms
61,108 KB
testcase_02 AC 497 ms
60,764 KB
testcase_03 AC 631 ms
62,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 a = 0; a < t; a++) {
            int n = sc.nextInt();
            HashMap<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                map.put(x, map.getOrDefault(x, 0) + 1);
            }
            PriorityQueue<Integer> queue = new PriorityQueue<>();
            for (int x : map.values()) {
                queue.add(-x);
            }
            int count = 0;
            while (queue.size() >= 3) {
                count++;
                int[] arr = new int[3];
                for (int i = 0; i < 3; i++) {
                    arr[i] = queue.poll() + 1;
                }
                for (int x : arr) {
                    if (x < 0) {
                        queue.add(x);
                    }
                }
            }
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
}
0