結果

問題 No.2334 Distinct Cards
ユーザー yukster714yukster714
提出日時 2023-06-11 12:26:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 581 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 12,848 KB
最終ジャッジ日時 2023-08-31 01:55:38
合計ジャッジ時間 2,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 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,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 71 ms
9,444 KB
testcase_13 AC 72 ms
9,444 KB
testcase_14 AC 73 ms
9,296 KB
testcase_15 AC 71 ms
9,352 KB
testcase_16 AC 72 ms
9,500 KB
testcase_17 AC 102 ms
12,780 KB
testcase_18 AC 98 ms
12,848 KB
testcase_19 AC 100 ms
12,776 KB
testcase_20 AC 27 ms
4,376 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 27 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)

int main()
{
    int n, k; cin>>n>>k;
    vector<int>a(n); 
    map<int,int>b; // kind -> count
    multimap<int,int>c; // count -> kind
    rep(i,n) cin>>a[i];
    rep(i,n) b[a[i]]++;
    for(auto it=b.begin();it!=b.end();it++){
        c.emplace(it->second,it->first);
    }
    int ans=0;
    int cnt=0;
    for(auto it=c.rbegin();it!=c.rend();it++){
        ans++;
        cnt+=it->first;
        if(cnt>=k) break;
    }
    cout << ans << endl;
    return 0;
}
0