提交记录 5439


用户 题目 状态 得分 用时 内存 语言 代码长度
TowardstheSun 1002i. 【模板题】多项式乘法 Accepted 100 64.21 ms 11948 KB C++11 1.25 KB
提交时间 评测时间
2018-08-22 21:34:19 2020-08-01 00:17:13
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
struct complex
{
	double r,i;
	complex(double a=0,double b=0):r(a),i(b){}
	complex operator+(complex x){return {r+x.r,i+x.i};}
	complex operator-(complex x){return {r-x.r,i-x.i};}
	complex operator*(complex x){return {r*x.r-i*x.i,r*x.i+i*x.r};}
	complex operator/(double x){return {r/x,i/x};}
	complex &operator*=(complex x){return *this=*this*x;}
	complex &operator/=(double x){return *this=*this/x;}
}a[300000],b[300000];
int rev[300000];
const double pi=acos(-1);
void fft(complex *c,int n,int f)
{
	for(int i=0;i<n;i++)
		if(rev[i]>i)swap(c[i],c[rev[i]]);
	for(int h=2;h<=n;h<<=1)
		for(int j=0;j<n;j+=h)
		{
			complex w=1,u(cos(pi*2/h),f*sin(pi*2/h));
			for(int k=j;k<j+h/2;k++)
			{
				complex x=c[k],y=c[k+h/2];
				c[k]=x+w*y;
				c[k+h/2]=x-w*y;
				w*=u;
			}
		}
	if(f==-1)for(int i=0;i<n;i++)a[i]/=n;
}
int p,q,n=1,k=-1,x;
int main()
{
	scanf("%d%d",&p,&q);p++;q++;
	for(int i=0;i<p;i++)scanf("%d",&x),a[i]=x;
	for(int i=0;i<q;i++)scanf("%d",&x),b[i]=x;
	while(n<=p+q)n<<=1,k++;
	for(int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<k);
	fft(a,n,1);
	fft(b,n,1);
	for(int i=0;i<n;i++)a[i]*=b[i];
	fft(a,n,-1);
	for(int i=0;i<p+q-1;i++)printf("%d ",int(a[i].r+.5));
	putchar('\n');
	return 0;
}


CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.046 ms9 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #263.681 ms11 MB + 604 KBAcceptedScore: 100

Subtask #1 Testcase #329.44 ms9 MB + 968 KBAcceptedScore: 0

Subtask #1 Testcase #429.427 ms9 MB + 956 KBAcceptedScore: 0

Subtask #1 Testcase #51.02 ms9 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #61.046 ms9 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #71.023 ms9 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #858.127 ms11 MB + 336 KBAcceptedScore: 0

Subtask #1 Testcase #958.123 ms11 MB + 336 KBAcceptedScore: 0

Subtask #1 Testcase #1052.276 ms11 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #1164.087 ms11 MB + 684 KBAcceptedScore: 0

Subtask #1 Testcase #1264.21 ms10 MB + 564 KBAcceptedScore: 0

Subtask #1 Testcase #131.016 ms9 MB + 176 KBAcceptedScore: 0


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