Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _2024
- {
- class Program
- {
- static void Main(string[] args)
- {
- string S = Console.ReadLine();
- int K = int.Parse(Console.ReadLine());
- char[] color = S.ToCharArray();
- int N = color.Length;
- int[] a = new int[N];
- for (int i = 0; i < N; i++)
- {
- a[i] = 1;
- {
- for (int j = 0; j < N; j++)
- if (i != j)
- if (color[i] == color[j])
- {
- a[i]++; a[j] = 0;
- }
- }
- }
- rep(ref a); int l1, l2, n;
- l1 = 0; n = 0;
- for (int i = 0; i < K ; i++)
- {
- if (a[i] == 0) break;
- l1 += a[i];
- }
- if (K > N) l2 = 1;
- else
- {
- for (int i = K - 1; i < N; i++)
- {
- if (a[K - 1] == a[i]) n++;
- else break;
- }
- if (n-K>=0)
- l2 = Fact(n) / (Fact(K) * Fact(n - K));
- else l2 = 1;
- }
- Console.WriteLine(l1 + " " + l2);
- Console.ReadKey();
- }
- static void rep(ref int[] a)
- {
- int x, i, j;
- int N = a.Length;
- for (i = 0; i < N; i++)
- {
- x = a[i];
- for (j = i - 1; j >= 0 && x > a[j]; j--)
- {
- a[j + 1] = a[j];
- }
- a[j + 1] = x;
- }
- }
- static int Fact(int n)
- {
- if (n == 0 || n == 1)
- return 1;
- else return n * Fact(n - 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement