提交记录 7923


用户 题目 状态 得分 用时 内存 语言 代码长度
sherlock 1002i. 【模板题】多项式乘法 Accepted 100 61.373 ms 11032 KB C++ 1.49 KB
提交时间 评测时间
2019-01-25 19:51:56 2020-08-01 01:10:18
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
using namespace std;
inline int read()
{
	int s=0,w=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')w=-1;c=getchar();}
	while(isdigit(c)){s=(s<<3)+(s<<1)+c-'0',c=getchar();}
	return s*w;
}
typedef double db;
const db pi=acos(-1.0);
const int MAXN=270010;
#define rg register int
struct Complex
{
	db x,y;
	Complex(db _x=0,db _y=0):x(_x),y(_y){}
	friend Complex operator+(const Complex &A,const Complex &B){return Complex(A.x+B.x,A.y+B.y);}
	friend Complex operator-(const Complex &A,const Complex &B){return Complex(A.x-B.x,A.y-B.y);}
	friend Complex operator*(const Complex &A,const Complex &B){return Complex(A.x*B.x-A.y*B.y,A.x*B.y+A.y*B.x);}
};
int pos[MAXN],limit=1,len;
inline void FFT(Complex *A,int type)
{
	for(rg i=0;i<limit;i++)
		if(i<pos[i])swap(A[i],A[pos[i]]);
	for(rg mid=1;mid<limit;mid<<=1)
	{
		Complex wn(cos(pi/mid),type*sin(pi/mid));
		for(rg j=0;j<limit;j+=(mid<<1))
		{
			Complex w(1,0);
			for(rg k=0;k<mid;k++,w=w*wn)
			{
				Complex a=A[j+k],b=w*A[j+mid+k];
				A[j+k]=a+b;
				A[j+mid+k]=a-b;
			}
		}
	}
}
int n,m;
Complex A[MAXN],B[MAXN];
int main()
{
	n=read(),m=read();
	for(rg i=0;i<=n;i++)A[i].x=read();
	for(rg i=0;i<=m;i++)B[i].x=read();
	while(limit<=m+n)limit<<=1,len++;
	for(rg i=1;i<limit;i++)
		pos[i]=((pos[i>>1]>>1)|(i&1)<<(len-1));
	FFT(A,1),FFT(B,1);
	for(rg i=0;i<limit;i++)A[i]=A[i]*B[i];
	FFT(A,-1);
	for(rg i=0;i<=n+m;i++)
		printf("%d ",(int)(A[i].x/limit+0.5));
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #1939.63 us8 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #260.741 ms10 MB + 712 KBAcceptedScore: 100

Subtask #1 Testcase #327.885 ms9 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #427.817 ms9 MB + 40 KBAcceptedScore: 0

Subtask #1 Testcase #5965.37 us8 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #6939.55 us8 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #7962.67 us8 MB + 284 KBAcceptedScore: 0

Subtask #1 Testcase #855.396 ms10 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #955.448 ms10 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #1050.038 ms10 MB + 176 KBAcceptedScore: 0

Subtask #1 Testcase #1161.04 ms10 MB + 792 KBAcceptedScore: 0

Subtask #1 Testcase #1261.373 ms9 MB + 672 KBAcceptedScore: 0

Subtask #1 Testcase #13962.4 us8 MB + 284 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:27:36 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠