列表

详情


NC225765. Cells

描述

Cuber QQ got a table of infinite size. He will consider the table rows numbered from top to bottom through , and the columns numbered from left to right through . Then he'll denote the cell in row x and column y as (x, y).

Initially, there are n trucks at cell (0, a_i) respectively. The goal is that each of the trucks have to go to one of the n destinations, located at cell . Cuber QQ has to make sure that there are no two trucks at the same destination. In another word, any two paths of the trucks are non-intersecting (no common points).

Each truck can go from cell (x, y) to one of two cells (x + 1, y) and (x, y - 1). And the truck can't have any chance of meeting any other trucks along the way.

Now can you help Cuber QQ to find the number of ways that trucks can achieve this goal.

输入描述

The first line contains one integer n (), where n is the number of trucks.

The second line contains n integers a_i (, ), which are the trucks' initial positions.

输出描述

Print the number of ways modulo 998244353 on the only line of output.

示例1

输入:

3
1 2 3

输出:

4

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 869ms, 内存消耗: 53624K, 提交时间: 2021-09-14 20:48:14

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e7+10,M=998244353,p=1e6;
LL R[N],A[N],B[N],n,c[N/10],m,l;
LL qmi(LL a,LL b)
{
	LL res=1;
	while(b)
	{
		if(b&1)res=res*a%M;
		a=a*a%M;
		b>>=1;
	}
	return res%M;
}
void NTT(LL *A,int f)
{
	for(int i=0;i<m;i++)if(i<R[i])swap(A[i],A[R[i]]);
	for(int h=2;h<=m;h<<=1)
	{
		int wn=qmi(3,(M-1)/h);
		if(f==-1)wn=qmi(wn,M-2);
		for(int j=0;j<m;j+=h)
		{
			int wk=1;
			for(int k=j;k<j+h/2;k++)
			{
				int x=A[k],y=(LL)wk*A[k+h/2]%M;
				A[k]=(x+y)%M;
				A[k+h/2]=(x-y+M)%M;
				wk=(LL)wk*wn%M;
			}
		}
	}
	if(f==-1)
	{
		int inv=qmi(m,M-2);
		for(int i=0;i<m;i++)A[i]=(LL)A[i]*inv%M;
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	LL ans=1,fac=1;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		A[c[i]]=1;
		B[p-c[i]]=1;
		fac=fac*i%M;
		ans=ans*qmi(fac,M-2)%M*(c[i]+1)%M;
	}

	l=-1;
	for(m=1;m<=p*2;m<<=1)l++;
	for(int i=0;i<m;i++)R[i]=(R[i>>1]>>1)|((i&1)<<l);

	NTT(A,1);NTT(B,1);
	for(int i=0;i<m;i++)A[i]=A[i]*B[i]%M;
	NTT(A,-1);
	for(int i=p+1;i<m;i++)if(A[i])ans=ans*qmi(i-p,A[i])%M;
	cout<<ans<<"\n";
	return 0;
}

上一题