PROBLEM_A: URAL 2024 Adventure Time

/*PROBLEM A : "UNSOLVED" */
/*TIME : ________________*/
#include "cstdio"
#include "cstring"
#include "cctype"
#include "algorithm"
#include "cmath"
#include "vector"
using namespace std;
#define Inc(i, a, b) for(int i = a; i < b; i++)
#define Dec(i, a, b) for(int i = a; i > b; i--)
#define Mem(a) memset(a, 0, sizeof(a))
#define Pii pair<int, int> 
#define Pdd pair<double, double>
#define Cin scanf
#define Put printf
#define CIN(a) scanf("%d", &a)
#define CII(a, b) scanf("%d%d", &a, &b)
#define CIS(a) scanf("%s", a)
#define PUT(a) printf("%d\n", a) 
#define PII(a, b) printf("%d %d\n", a, b)
#define PUS(a) printf("%s\n", a)
#define Pub push_back
#define Mpi make_pair
#define ll long long
#define maxn 100005
#define pi acos(-1)
#define eps 1e-10

char  st[maxn];
int n, k;
int is[27][2];
struct node {
	int xc, no;
} ch[27];
bool comp(node a, node b) {
	return a.no > b.no;
}
int C(int a, int b) {
	int sum = 1;
	Inc(i, 0, b) sum *= (a - i), sum /= i + 1;
	return sum;
}
int main() {
	while(~Cin("%s%d", st, &k)) {
		n = strlen(st);
		Mem(is), Mem(ch);
		Inc(i, 0, 26) ch[i].xc = i, ch[i].xc = 0;
		ch[26].no = -1;
		Inc(i, 0, n) ch[st[i] - 'a'].no++;
		sort(ch, ch + 26, comp);
		int tmp = 1, num = 1;
		Inc(i, 1, 27) {
			if(ch[i].no == ch[i - 1].no) tmp++;
			else {
				is[num][0] = tmp, tmp = 1;
				is[num++][1] = ch[i - 1].no;
			}
			if(ch[i].no == 0) break;
		}
		int it[27][2];
		Mem(it);
		Inc(i, 1, 27) {
			it[i][0] += it[i - 1][0] + is[i][0];
			it[i][1] += it[i - 1][1] + is[i][0] * is[i][1]; 
		}
		bool flag = 0;
		Inc(i, 1, 27) {
			if(it[i][0] >= k) {
				int t = k - is[i - 1][0];
				PII(it[i - 1][1] + t * is[i][1], C(is[i][0], t));
				flag = 1;
				break;
			}
			if(is[i][0] == 0) break;
		}
		if(!flag) PII(it[26][1], 1);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值