結果

問題 No.120 傾向と対策:門松列(その1)
ユーザー kou6839kou6839
提出日時 2015-01-14 01:29:51
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,037 ms / 5,000 ms
コード長 1,346 bytes
コンパイル時間 2,813 ms
コンパイル使用メモリ 76,840 KB
実行使用メモリ 75,160 KB
最終ジャッジ日時 2023-09-04 12:48:09
合計ジャッジ時間 7,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 867 ms
69,408 KB
testcase_01 AC 1,037 ms
73,396 KB
testcase_02 AC 666 ms
61,620 KB
testcase_03 AC 1,029 ms
75,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t= sc.nextInt();
        for(int i=0;i<t;i++){
        	int n = sc.nextInt();
        	HashMap<Integer,Integer> matu = new HashMap<>();
        	for(int j=0;j<n;j++){
        		int a = sc.nextInt();
        		if(!matu.containsKey(a)) matu.put(a, 0);
        		matu.put(a, matu.get(a)+1);
        	}
        	int ans=0;
        	tt:while(true){
        		if(matu.size()<3) break;
        		ans++;
        		int count=1;
        		List<Map.Entry> entries = new ArrayList<Map.Entry>(matu.entrySet());
        		Collections.sort(entries, new Comparator(){
        		    public int compare(Object o1, Object o2){
        		        Map.Entry e1 =(Map.Entry)o1;
        		        Map.Entry e2 =(Map.Entry)o2;
        		        return -((Integer)e1.getValue()).compareTo((Integer)e2.getValue());
        		    }
        		});
        		for(Map.Entry b: entries ){
        			matu.put((Integer)b.getKey(), matu.get((Integer)b.getKey())-1);
        			if(count==3) break;
        			count++;
        		}
        		Object[] aaa = matu.keySet().toArray();
        		for(Object aa:aaa){
        			if(matu.get(aa)==0) matu.remove(aa);
        		}
        	}
        	System.out.println(ans);
        }
	}
}
0