結果

問題 No.2334 Distinct Cards
ユーザー anonymouslyanonymously
提出日時 2023-06-02 23:10:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 2,719 ms
コンパイル使用メモリ 180,424 KB
実行使用メモリ 10,184 KB
最終ジャッジ日時 2023-08-28 05:40:48
合計ジャッジ時間 3,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 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,380 KB
testcase_12 AC 62 ms
7,584 KB
testcase_13 AC 62 ms
7,548 KB
testcase_14 AC 63 ms
7,688 KB
testcase_15 AC 63 ms
7,564 KB
testcase_16 AC 62 ms
7,660 KB
testcase_17 AC 76 ms
10,184 KB
testcase_18 AC 74 ms
10,136 KB
testcase_19 AC 77 ms
10,004 KB
testcase_20 AC 27 ms
4,380 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 27 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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