CF1753B 题解

Preface#

题目传送门

Solution#

定理:n!(n+1)=(n+1)!

这题就是围绕以上定理展开的。

如果加入一个数 ai 满足 count(ai)>ai,则根据定理,将 count(ai+1)+1,在将 ai=0。其中 count(ai) 表示 ai 出现的次数

如果 i=1nai!x! 即满足 (i=1x1count(i))=0

Code#

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <cmath>
#include <sstream>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

#define x first
#define y second
#define IOS ios::sync_with_stdio(false)
#define cit cin.tie(0)
#define cot cout.tie(0)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 500010, M = 100010, MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int n, x;
int cnt[N];

void solve()
{
	cin >> n >> x;
	for (int i = 1; i <= n; i ++ )
	{
		int t;
		cin >> t;
		cnt[t] ++ ;
		while (cnt[t] >= t + 1)
		{
			cnt[t + 1] += cnt[t] / (t + 1);
			cnt[t] %= (t + 1);
			t ++ ;
		}
	}
	
	bool flag = true;
	for (int i = 1; i < x; i ++ )
		if (cnt[i])
		{
			flag = false;
			break;
		}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main()
{
	IOS;
	cit, cot;
	int T = 1;
//	cin >> T;
	while (T -- ) solve();
	return 0;
}
posted @   hcywoi  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示
主题色彩