QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352148#8329. Excusegrass8cowWA 665ms19328kbC++172.3kb2024-03-12 21:58:562024-03-12 21:58:58

Judging History

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

  • [2024-03-12 21:58:58]
  • 评测
  • 测评结果:WA
  • 用时:665ms
  • 内存:19328kb
  • [2024-03-12 21:58:56]
  • 提交

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],fz2[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],g_[101000],a[100100],P2[101000];
void cdq(int l,int r){
	if(l==r){
		if(l>0)g[l]=1ll*g[l]*i2[l]%mod*qpow(1-i2[l],mod-2)%mod;
		return;
	}
	int mid=(l+r)>>1;
	cdq(l,mid);
	init((r-l+1)*2);
	for(int i=0;i<L;i++)fz1[i]=fz2[i]=0;
	for(int i=0;i<=mid-l;i++)fz1[i]=g[i+l];
	for(int i=1;i<=r-l;i++)fz2[i]=ij[i+1];
	NTT(fz1,1),NTT(fz2,1); 
	for(int i=0;i<L;i++)fz1[i]=1ll*fz1[i]*fz2[i]%mod;
	NTT(fz1,0);
	for(int i=mid+1;i<=r;i++)(g[i]+=fz1[i-l])%=mod;
	cdq(mid+1,r);
}
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;
	g[0]=1;
	cdq(0,n);
	Inv(g,g_,n+1);
	init(n*2+3);for(int i=n+1;i<L;i++)g_[i]=0;
	memset(fz1,0,sizeof(fz1)); 
	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: 11996kb

input:

1

output:

499122177

result:

ok 1 number(s): "499122177"

Test #2:

score: 0
Accepted
time: 2ms
memory: 11988kb

input:

3

output:

561512450

result:

ok 1 number(s): "561512450"

Test #3:

score: 0
Accepted
time: 2ms
memory: 14148kb

input:

10

output:

609769250

result:

ok 1 number(s): "609769250"

Test #4:

score: 0
Accepted
time: 2ms
memory: 14076kb

input:

1000

output:

475714976

result:

ok 1 number(s): "475714976"

Test #5:

score: 0
Accepted
time: 3ms
memory: 12164kb

input:

1024

output:

178624793

result:

ok 1 number(s): "178624793"

Test #6:

score: -100
Wrong Answer
time: 665ms
memory: 19328kb

input:

100000

output:

542890838

result:

wrong answer 1st numbers differ - expected: '537516197', found: '542890838'