結果
| 問題 |
No.2334 Distinct Cards
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2023-06-03 10:45:31 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 2,000 ms |
| コード長 | 858 bytes |
| コンパイル時間 | 1,134 ms |
| コンパイル使用メモリ | 114,580 KB |
| 実行使用メモリ | 33,152 KB |
| 最終ジャッジ日時 | 2024-12-29 02:37:12 |
| 合計ジャッジ時間 | 3,768 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq;
using System.Collections.Generic;
using System;
public class Hello
{
static void Main()
{
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var k = int.Parse(line[1]);
line = Console.ReadLine().Trim().Split(' ');
var a = Array.ConvertAll(line, int.Parse);
getAns(n, k, a);
}
static void getAns(int n, int k, int[] a)
{
var d = new Dictionary<int, int>();
foreach (var x in a)
if (d.ContainsKey(x)) d[x]++;
else d[x] = 1;
var ans = 0;
var c = 0;
foreach (var x in d.OrderByDescending(x => x.Value))
{
if (c + x.Value < k) { ans++; c += x.Value; }
else { Console.WriteLine(ans + 1); return; }
}
Console.WriteLine(ans);
}
}
bluemegane