QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282647#7873. Since A Lightzhouhuanyi0 268ms16152kbC++203.3kb2023-12-12 17:10:272023-12-12 17:10:28

Judging History

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

  • [2023-12-12 17:10:28]
  • 评测
  • 测评结果:0
  • 用时:268ms
  • 内存:16152kb
  • [2023-12-12 17:10:27]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#define N 100000
#define M 262144
#define K 20
#define g 3
#define mod 998244353
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
int n,d,ans,length,A[M+1],B[M+1],wn[K+1][M+1],wn2[K+1][M+1],rev[M+1],num[M+1];
struct matrix
{
	vector<int>p[5][5];
};
matrix e,nw,dres,c,zero;
vector<int>zro;
void NTT(int limit,int *s,int type)
{
	int s1,s2;
	for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(limit>>1):0);
	for (int i=0;i<limit;++i)
		if (rev[i]>i)
			swap(s[i],s[rev[i]]);
	if (type==1)
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
	}
	else
	{
		for (int i=2;i<=limit;i<<=1)
			for (int j=0;j+i-1<limit;j+=i)
				for (int k=j;k<j+(i>>1);++k)
					s1=s[k],s2=1ll*s[k+(i>>1)]*wn2[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
		s1=fast_pow(limit,mod-2);
		for (int i=0;i<limit;++i) s[i]=1ll*s[i]*s1%mod;
	}
	return;
}
vector<int>operator + (vector<int>a,vector<int>b)
{
	if (a.size()<b.size()) swap(a,b);
	for (int i=0;i<b.size();++i) Adder(a[i],b[i]);
	return a;
}
vector<int>operator * (vector<int>a,vector<int>b)
{
	if (a.empty()||b.empty()) return zro;
	int limit=1;
	vector<int>cs(min((int)(a.size()+b.size()-1),d));
	if (min(a.size(),b.size())<=10)
	{
		for (int i=0;i<a.size();++i)
			for (int j=0;j<b.size()&&i+j<cs.size();++j)
				Adder(cs[i+j],1ll*a[i]*b[j]%mod);
		return cs;
	}
	else
	{
		while (limit<=a.size()+b.size()) limit<<=1;
		for (int i=0;i<=limit;++i) A[i]=B[i]=0;
		for (int i=0;i<a.size();++i) A[i]=a[i];
		for (int i=0;i<b.size();++i) B[i]=b[i];
		NTT(limit,A,1),NTT(limit,B,1);
		for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
		NTT(limit,A,-1);
		for (int i=0;i<cs.size();++i) cs[i]=A[i];
	}
	return cs;
}
matrix operator * (matrix a,matrix b)
{
	c=zero;
	for (int k=0;k<5;++k)
		for (int i=0;i<5;++i)
			for (int j=0;j<5;++j)
				c.p[i][j]=c.p[i][j]+a.p[i][k]*b.p[k][j];
	return c;
}
matrix fast_pows(matrix a,int b)
{
	matrix res=e,mul=a;
	while (b)
	{
		if (b&1) res=res*mul;
		mul=mul*mul,b>>=1;
	}
	return res;
}
int main()
{
	int rst;
	for (int i=2;i<=M;i<<=1)
	{
		num[i]=++length,rst=fast_pow(g,(mod-1)/i);
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*rst%mod) wn[num[i]][j]=res;
		rst=fast_pow(g,(mod-1)/i*(i-1));
		for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*rst%mod) wn2[num[i]][j]=res;
	}
	for (int i=0;i<5;++i) e.p[i][i]={1};
	n=read(),d=read(),nw.p[0][0]={0,0,1},nw.p[0][1]={0,2},nw.p[0][2]={1},nw.p[1][0]={0,1},nw.p[1][1]={1},nw.p[2][0]={1};
	nw.p[1][3]=nw.p[3][3]=nw.p[3][4]=nw.p[4][3]={1},dres=fast_pows(nw,n);
	for (int i=0;i<=2;++i)
		if (d-1<dres.p[i][3].size())
			Adder(ans,dres.p[i][3][d-1]);
	printf("%d\n",ans);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 1
Accepted
time: 2ms
memory: 16152kb

input:

1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 5ms
memory: 16132kb

input:

2 1

output:

2

result:

ok single line: '2'

Test #3:

score: -1
Wrong Answer
time: 0ms
memory: 16072kb

input:

3 2

output:

6

result:

wrong answer 1st lines differ - expected: '3', found: '6'

Subtask #2:

score: 0
Wrong Answer

Test #26:

score: 7
Accepted
time: 3ms
memory: 16124kb

input:

380 59

output:

718355613

result:

ok single line: '718355613'

Test #27:

score: -7
Wrong Answer
time: 5ms
memory: 8064kb

input:

164 46

output:

706900206

result:

wrong answer 1st lines differ - expected: '353450103', found: '706900206'

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 11ms
memory: 10236kb

input:

413 652

output:

341200236

result:

wrong answer 1st lines differ - expected: '170600118', found: '341200236'

Subtask #4:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 114ms
memory: 11424kb

input:

4495 4498

output:

751171398

result:

wrong answer 1st lines differ - expected: '375585699', found: '751171398'

Subtask #5:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 8ms
memory: 9980kb

input:

158314621 32

output:

931483922

result:

wrong answer 1st lines differ - expected: '465741961', found: '931483922'

Subtask #6:

score: 0
Wrong Answer

Test #46:

score: 0
Wrong Answer
time: 268ms
memory: 10384kb

input:

812922977 1762

output:

857746161

result:

wrong answer 1st lines differ - expected: '927995257', found: '857746161'

Subtask #7:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

320076133 78121

output:


result: