結果
問題 | No.120 傾向と対策:門松列(その1) |
ユーザー | Daigo HIROOKA |
提出日時 | 2018-05-23 03:13:47 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 805 ms / 5,000 ms |
コード長 | 715 bytes |
コンパイル時間 | 3,576 ms |
コンパイル使用メモリ | 74,256 KB |
実行使用メモリ | 62,436 KB |
最終ジャッジ日時 | 2023-09-11 01:34:31 |
合計ジャッジ時間 | 7,724 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 767 ms
62,184 KB |
testcase_01 | AC | 805 ms
62,360 KB |
testcase_02 | AC | 554 ms
62,128 KB |
testcase_03 | AC | 793 ms
62,436 KB |
ソースコード
import java.util.*; public class No120{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t < T; t++){ int N = sc.nextInt(); int[] l = new int[N]; int[] count = new int[N]; for(int n = 0; n < N; n++){ l[n] = sc.nextInt(); } Arrays.sort(l); int kind = 0; int c = 1; for(int i = 1; i < N; i++){ if(l[i] == l[i-1]){ c++; }else{ count[kind++] = c; c = 1; } } count[kind++] = c; Arrays.sort(count); int max = 0; while(N-2 > 0 && count[N-3]>0){ max++; count[N-3]--; count[N-2]--; count[N-1]--; Arrays.sort(count); } System.out.println(max); } } }