結果
| 問題 | No.120 傾向と対策:門松列(その1) | 
| コンテスト | |
| ユーザー |  chiho_miyako | 
| 提出日時 | 2015-04-22 01:32:03 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 830 ms / 5,000 ms | 
| コード長 | 1,338 bytes | 
| コンパイル時間 | 2,420 ms | 
| コンパイル使用メモリ | 80,220 KB | 
| 実行使用メモリ | 49,540 KB | 
| 最終ジャッジ日時 | 2024-07-04 23:42:59 | 
| 合計ジャッジ時間 | 7,177 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 4 | 
ソースコード
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        for(int m=0; m<n; m++){
            int t = koko.nextInt();
            int[] l = new int[t];
            ArrayList<Integer> count = new ArrayList<>();
            for(int i=0; i<t; i++){
                l[i]=koko.nextInt();
            }
            Arrays.sort(l);
            int cou = 1;
            for(int i=1; i<t; i++){
                if(l[i]==l[i-1]){
                    cou++;
                }else{
                    count.add(cou);
                    cou=1;
                }
            }
            count.add(cou);
            int kumi =0;
            Collections.sort(count, Collections.reverseOrder());
            while(count.size()>2&&count.get(2)>0){
                kumi++;
                int a = count.get(0)-1;
                int b = count.get(1)-1;
                int c = count.get(2)-1;
                count.remove(0);
                count.remove(0);
                count.remove(0);
                count.add(a);
                count.add(b);
                count.add(c);
                Collections.sort(count, Collections.reverseOrder());
            }
            System.out.println(kumi);
        }
    }
}
            
            
            
        