結果
| 問題 |
No.120 傾向と対策:門松列(その1)
|
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2015-01-14 01:29:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,029 ms / 5,000 ms |
| コード長 | 1,346 bytes |
| コンパイル時間 | 2,579 ms |
| コンパイル使用メモリ | 81,180 KB |
| 実行使用メモリ | 73,616 KB |
| 最終ジャッジ日時 | 2024-06-22 11:24:45 |
| 合計ジャッジ時間 | 7,734 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 |
ソースコード
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);
}
}
}
kou6839