結果

問題 No.2334 Distinct Cards
ユーザー tentententen
提出日時 2023-06-05 10:01:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 2,123 bytes
コンパイル時間 3,429 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 64,948 KB
最終ジャッジ日時 2023-08-28 09:26:19
合計ジャッジ時間 9,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,728 KB
testcase_01 AC 43 ms
49,616 KB
testcase_02 AC 43 ms
49,536 KB
testcase_03 AC 44 ms
49,444 KB
testcase_04 AC 46 ms
49,736 KB
testcase_05 AC 43 ms
49,304 KB
testcase_06 AC 44 ms
49,336 KB
testcase_07 AC 61 ms
50,096 KB
testcase_08 AC 61 ms
50,216 KB
testcase_09 AC 60 ms
50,180 KB
testcase_10 AC 59 ms
50,488 KB
testcase_11 AC 60 ms
50,088 KB
testcase_12 AC 324 ms
60,700 KB
testcase_13 AC 332 ms
60,980 KB
testcase_14 AC 322 ms
61,088 KB
testcase_15 AC 330 ms
61,028 KB
testcase_16 AC 333 ms
60,912 KB
testcase_17 AC 358 ms
64,672 KB
testcase_18 AC 346 ms
64,680 KB
testcase_19 AC 370 ms
64,948 KB
testcase_20 AC 216 ms
55,928 KB
testcase_21 AC 224 ms
55,844 KB
testcase_22 AC 222 ms
55,708 KB
testcase_23 AC 43 ms
49,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            counts.put(x, counts.getOrDefault(x, 0) + 1);
        }
        int[] values = new int[counts.size()];
        int idx = 0;
        for (int x : counts.values()) {
            values[idx++] = x;
        }
        Arrays.sort(values);
        int sum = 0;
        TreeMap<Integer, Integer> places = new TreeMap<>();
        for (int i = 0; i < idx; i++) {
            sum += values[idx - i - 1];
            places.put(sum, i + 1);
        }
        System.out.println(places.ceilingEntry(k).getValue());
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0