結果

問題 No.2334 Distinct Cards
ユーザー V_MelvilleV_Melville
提出日時 2023-06-02 22:17:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 5,354 ms
コンパイル使用メモリ 265,656 KB
実行使用メモリ 8,712 KB
最終ジャッジ日時 2023-08-28 04:01:21
合計ジャッジ時間 4,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    
    vector<int> cnt(n);
    rep(i, n) cnt[a[i]]++;
    
    map<int, int> mp; 
    set<int> s;
    rep(i, n) {
        if (s.count(a[i])) continue;
        mp[cnt[a[i]]]++;
        s.insert(a[i]);
    }
    
    vector<P> ps;
    for (auto [c, y] : mp) {
        ps.emplace_back(c, y);
    }
    
    sort(ps.rbegin(), ps.rend());
    
    int ans = 0;
    for (auto [c, y] : ps) {
        while (y) {
            ans++;
            int nc = c;
            k -= nc;
            if (k <= 0) {
                cout << ans << '\n';
                return 0;
            }
            y--;
        }
    }
    
    return 0;
}
0