結果

問題 No.2334 Distinct Cards
ユーザー anonymously
提出日時 2023-06-02 23:10:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 184,332 KB
実行使用メモリ 10,552 KB
最終ジャッジ日時 2024-12-28 21:59:40
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
	size_t n,k;
	cin >> n >> k;
	
	//整数の個数をカウント
	map<int, size_t> M;
	
	for(size_t i=0;i<n;i++){
		int a;
		cin >> a;
		M[a]++;
	}
	
	//個数⇒整数(個数の多いほうから)
	map<size_t, vector<int>, greater<size_t>> IM;
	for(pair<int,size_t> p : M){
#ifdef DEBUG
		cout << p.first << ' ' << p.second << endl << flush;
#endif
		IM[p.second].push_back(p.first);
	}
	
	size_t count=0; //合計枚数
	int cnt=0; //種類数
	for(pair<size_t,vector<int>> p : IM){
		for(int i : p.second){
#ifdef DEBUG
			cout << p.first << ' ' << i << endl << flush;
#endif
			count+=p.first;
			cnt++;
			if(count>=k){
				break;
			}
		}
		if(count>=k){
			break;
		}
	}
	
	//最小の種類数を出力
	cout << cnt << endl;
}
0