結果

問題 No.2334 Distinct Cards
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-06-02 22:58:54
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 2,574 ms
コンパイル使用メモリ 146,736 KB
実行使用メモリ 4,588 KB
最終ジャッジ日時 2023-08-28 05:22:46
合計ジャッジ時間 3,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut input_iter = input.split_whitespace();
    let n: usize = input_iter.next().unwrap().parse().unwrap();
    let k: usize = input_iter.next().unwrap().parse().unwrap();

    let mut a = Vec::new();
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let input_iter = input.split_whitespace();
    for num in input_iter {
        let num: usize = num.parse().unwrap();
        a.push(num);
    }

    let mut counts = vec![0; n + 1];
    for i in 0..n {
        counts[a[i]] += 1;
    }
    counts.sort_by(|a, b| b.cmp(a));
    let mut position = 0;
    let mut sum = 0;
    for i in 0..n + 1 {
        sum += counts[position];
        if sum >= k {
            position = i + 1;
            break;
        }
    }

    println!("{}", position);
}
0