跳到正文

题解

题解 CF1327E 【Count The Blocks】

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

文章信息

收录
2026年6月14日
更新
2026年6月14日
篇幅
约 2 分钟
获赞
5
题目
CF1327E

版本

  1. v1当前

计算贡献。

假设知道有一个长度为 lenlen 的串,分类讨论。

如果 len=nlen=n 只有 1010 种情况(全部为0,1…90,1\dots9)

如果这个串的左端点为 11 或右端点为 nn: 则有 10×9×10n−len−110\times 9\times 10^{n-len-1}种方法

(1010(自己可以随便选)×\times 99 (最近的一位不能相同) ×10n−len−1\times 10^{n-len-1}(其它位随便选)

否则: 10×92×10n−len−210\times 9^2\times 10^{n-len-2}种方法

(1010(自己可以随便选)×\times 929^2 (最近的两位不能相同) ×10n−len−2\times 10^{n-len-2}(其它位随便选)

可以发现,我们可以枚举 lenlen 求答案。

对于第一种情况,特判 n=lenn=len。

第二种情况在每一种 lenlen 只会出现两次,第三种情况有 n−len−1n-len-1 次,乘上对应贡献即可,

C++
#include<bits/stdc++.h>
using namespace std;
#define re register
#define int long long
#define M 998244353
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int t,n,m,k,x,jc[400002],ans;
signed main(){
	n=read();jc[0]=1;for(re int i=1;i<=n*2;++i)jc[i]=jc[i-1]*10%M;
	for(re int i=1;i<=n;++i){
		ans=0;
		if(i==n)ans+=10;
		else if(i==n-1)ans+=180;
		else{
		ans+=(n-i-1)*jc[n-i-2]%M*810ll%M;
		ans+=jc[n-i-1]*180ll%M;
		}
		printf("%lld ",ans%M);
	}
}
原文
存档评论2 条抓取于