結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2020-11-17 20:13:43 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 725 ms / 5,000 ms | 
| コード長 | 1,138 bytes | 
| コンパイル時間 | 2,278 ms | 
| コンパイル使用メモリ | 79,944 KB | 
| 実行使用メモリ | 60,068 KB | 
| 最終ジャッジ日時 | 2024-07-23 08:27:04 | 
| 合計ジャッジ時間 | 6,248 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
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);
    }
}
            
            
            
        