提交记录 17152


用户 题目 状态 得分 用时 内存 语言 代码长度
Z_301 1002i. 【模板题】多项式乘法 Accepted 100 115.648 ms 134760 KB C++11 1.21 KB
提交时间 评测时间
2021-12-02 16:38:55 2021-12-02 16:38:59
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
struct cp
{
	double a,b;
	cp(double ai=0,double bi=0){a=ai,b=bi;}
	cp operator+(cp x){return cp(a+x.a,b+x.b);}
	cp operator-(cp x){return cp(a-x.a,b-x.b);}
	cp operator*(cp x){return cp(a*x.a-b*x.b,a*x.b+b*x.a);}
	cp operator/(cp x){return cp((a*x.a+b*x.b)/(x.a*x.a+x.b*x.b),(b*x.a-a*x.b)/(x.a*x.a+x.b*x.b));}
	cp operator+=(cp x){return *this=*this+x;}
	cp operator-=(cp x){return *this=*this-x;}
	cp operator*=(cp x){return *this=*this*x;}
	cp operator/=(cp x){return *this=*this/x;}
};
const int MAXN=4e6+10;
cp a[MAXN],b[MAXN];
int n,m,lim;
void fft(cp *a,int lim,int type)
{
	if(lim==1)return;
	int hl=lim>>1;cp a1[hl],a2[hl];
	for(int i=0;i<hl;i++)a1[i]=a[i<<1],a2[i]=a[i<<1|1];
	fft(a1,hl,type),fft(a2,hl,type);
	cp wi(cos(pi*2/lim),type*sin(pi*2/lim)),w(1,0);
	for(int i=0;hl>i;i++,w*=wi)
		a[i]=a1[i]+w*a2[i],a[i+hl]=a1[i]-w*a2[i];
}
int main()
{
	scanf("%d%d",&n,&m);n++,m++;
	for(int i=0,ai;n>i;i++)scanf("%d",&ai),a[i]=cp(ai,0);
	for(int j=0,bi;m>j;j++)scanf("%d",&bi),b[j]=cp(bi,0);
	lim=1;
	while(lim<=n+m)lim<<=1;
	fft(a,lim,1),fft(b,lim,1);
	for(int i=0;lim>i;i++)a[i]*=b[i];
	fft(a,lim,-1);
	for(int i=0;n+m-1>i;i++)
		printf("%d ",int(a[i].a/lim+0.5));
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #113.678 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #2114.409 ms131 MB + 536 KBAcceptedScore: 100

Subtask #1 Testcase #360.44 ms126 MB + 388 KBAcceptedScore: 0

Subtask #1 Testcase #460.624 ms126 MB + 376 KBAcceptedScore: 0

Subtask #1 Testcase #513.676 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #613.677 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #714.413 ms122 MB + 108 KBAcceptedScore: 0

Subtask #1 Testcase #8109.318 ms131 MB + 268 KBAcceptedScore: 0

Subtask #1 Testcase #9108.519 ms131 MB + 268 KBAcceptedScore: 0

Subtask #1 Testcase #10102.622 ms131 MBAcceptedScore: 0

Subtask #1 Testcase #11114.918 ms131 MB + 616 KBAcceptedScore: 0

Subtask #1 Testcase #12115.648 ms130 MB + 496 KBAcceptedScore: 0

Subtask #1 Testcase #1314.041 ms122 MB + 108 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-27 07:59:02 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用