[ARC035B] アットコーダー王国のコンテスト事情 题解

前置芝士##

排列组合

分析##

明显的贪心,第一问与此题思路相似,优先选择做时间少的,可以尽可能让后面的罚时尽量的小。

难点在第二问,第二问问的是有几种可能性,有个显然的结论:相同做题时间的题目,位置调换答案仍然相同。

那么可以用 桶+排列组合 来解决:

用桶储存这个做题时间的出现次数 \(b_i\),然后进行遍历,如果这个数出现多次,那么 \(ans = ans \times b_i!\)

注意输出答案时,结尾要有换行。AT 老 bug 了

Accpeted Code##

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e4 + 5;
const int mod = 1e9 + 7;
int t[N], b[N], now, mx, ans1, ans2 = 1;
int fac(int n)
{
	int res = 1;
	for (int i = 1; i <= n; i++)res = (res * i) % mod;
	return res;
}
signed main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> t[i];
	sort(t + 1, t + n + 1);
	for (int i = 1; i <= n; i++)
	{
		now += t[i];
		mx = max(mx, t[i]);
		b[t[i]]++;
		ans1 += now;
	}
	for (int i = 1; i <= mx; i++)
		if (b[i])ans2 = (ans2 * fac(b[i])) % mod;
	cout << ans1 << endl << ans2 << endl;
	return 0;
}
posted @   Manipula  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示
主题色彩
主题色彩