結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー chiho_miyakochiho_miyako
提出日時 2015-04-22 01:32:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 738 ms / 5,000 ms
コード長 1,338 bytes
コンパイル時間 2,439 ms
コンパイル使用メモリ 76,656 KB
実行使用メモリ 62,316 KB
最終ジャッジ日時 2023-09-18 07:36:22
合計ジャッジ時間 6,970 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 680 ms
62,316 KB
testcase_01 AC 738 ms
61,492 KB
testcase_02 AC 559 ms
61,092 KB
testcase_03 AC 723 ms
61,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        }
    }
}
0