QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352144#8329. Excusegrass8cowWA 3ms3996kbC++172.1kb2024-03-12 21:51:042024-03-12 21:51:04

Judging History

你现在查看的是最新测评结果

  • [2024-03-12 21:51:04]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3996kb
  • [2024-03-12 21:51:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,jc[101000],ij[101000],p2[100100],i2[100100];
const int mod=998244353,G=3,GI=(mod+1)/3,inv2=(mod+1)/2;
int qpow(int a,ll b){
	int c=1;
	for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod; 
	}
	return c;
}
int lb[1<<20],L;
void init(int n){
	L=1;while(L<=n)L<<=1;
	for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(int *a,int fl){
	for(int i=0;i<L;i++)if(i<lb[i])swap(a[i],a[lb[i]]);
	for(int o=1;o<L;o<<=1){
		int Wn=qpow(fl?G:GI,(mod-1)/(o<<1));
		for(int i=0;i<L;i+=(o<<1))for(int j=0,w=1;j<o;j++,w=1ll*w*Wn%mod){
			int x=a[i+j],y=1ll*a[i+j+o]*w%mod;
			a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
		}
	}
	if(!fl){
		int I=qpow(L,mod-2);
		for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod; 
	}
}
int fz1[1<<20];
void Inv(int *a,int *b,int n){
	if(n==1){b[0]=qpow(a[0],mod-2);return;}
	int N=(n+1)>>1;Inv(a,b,N);
	init(2*n+5);
	for(int i=0;i<L;i++)fz1[i]=0;
	for(int i=0;i<n;i++)fz1[i]=a[i];
	for(int i=N;i<L;i++)b[i]=0;
	NTT(fz1,1),NTT(b,1);
	for(int i=0;i<L;i++)fz1[i]=1ll*b[i]*(2-1ll*b[i]*fz1[i]%mod)%mod;
	NTT(fz1,0);
	for(int i=0;i<n;i++)b[i]=fz1[i];
}
int g[100010],f[101000],g_[101000],a[100100],P2[101000];
int main(){
	scanf("%d",&n);
	jc[0]=ij[0]=p2[0]=i2[0]=P2[0]=1;
	for(int i=1;i<=n+1;i++)jc[i]=1ll*i*jc[i-1]%mod,ij[i]=qpow(jc[i],mod-2),p2[i]=2*p2[i-1]%mod,i2[i]=1ll*inv2*i2[i-1]%mod,
	P2[i]=1ll*P2[i-1]*p2[i]%mod;
	for(int i=0;i<=n;i++)f[i]=ij[i+1];
	//g(x)=f(x/2)g(x/2)
	//g_i=2^_{-i}*sum f_ig_{x-i}
	g[0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++)(g[i]+=1ll*g[i-j]*f[j]%mod)%=mod;
		g[i]=1ll*g[i]*i2[i]%mod*qpow(1-i2[i],mod-2)%mod;
	}
	Inv(g,g_,n+1);
	init(n*2+3);for(int i=n+1;i<L;i++)g_[i]=0;
	for(int i=0;i<=n;i++)fz1[i]=ij[i];
	NTT(g_,1),NTT(fz1,1);for(int i=0;i<L;i++)g_[i]=1ll*g_[i]*fz1[i]%mod;
	NTT(g_,0);
	for(int i=0;i<=n;i++)g_[i]=1ll*g_[i]*P2[i]%mod;
	for(int i=0,s=0;i<=n;i++)a[i]=1ll*s*qpow(P2[i],mod-2)%mod,(s+=g_[i])%=mod;
	int ans=0;
	for(int i=0;i<=n;i++)(ans+=1ll*a[i]*g[n-i]%mod)%=mod;
	return printf("%d",(1ll*ans*jc[n]%mod+mod)%mod),0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3980kb

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

score: -100
Wrong Answer
time: 3ms
memory: 3996kb

input:

1000

output:

10832169

result:

wrong answer 1st numbers differ - expected: '475714976', found: '10832169'