跳到正文

题解

题解:CF2247B Yet Another Constructive

shimizu_kiouka约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年7月19日
收录
2026年7月20日
更新
2026年11月9日
篇幅
约 2 分钟
获赞
4
题目
CF2247B

版本

  1. v1当前

题解:CF2247B Yet Another Constructive 题解。

构造一个长为 nn 的正整数序列,要求子序列之和能被 mm 整除的最短子序列长度为 kk。

我们可以用贪心解决此题。

由于序列中都是正整数,则 m<km<k 的情况是不可能的。

对于其他可行的情况,首先先往序列中添加 k−1k-1 个 11,然后再添加 m−k+1m-k+1,这样一来序列中就有 kk 个元素,且和恰好为 mm。接下来只要再添加 11 直到序列长度到 nn 即可,显然,这样的序列能被 mm 整除的最短子序列长度只能为 kk。

那么这题就解决了。

C++
//coder:shimizu_kiouka
//problem:#CF2247B
//2026/07/18
//And in that light,I find the deliverance.
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t;
ll n,k,m;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		ll a[303030];
		ll cnt=0;
		cin>>n>>k>>m;
		if(k>m){
			cout<<"NO\n";
			continue;
		}
		cout<<"YES\n";
		for(int i=1;i<k;i++){
			a[++cnt]=1;
		}
		a[++cnt]=m-k+1;
		while(cnt<=n){
			a[++cnt]=1;
		}
		for(int i=1;i<cnt;i++){
			cout<<a[i]<<' ';
		}
		cout<<'\n';
	}
}
原文
存档评论1 条抓取于