提交记录 17026


用户 题目 状态 得分 用时 内存 语言 代码长度
kpeaker 1002. 测测你的多项式乘法 Time Limit Exceeded 0 5 s 36 KB C++ 2.40 KB
提交时间 评测时间
2021-11-29 12:00:51 2021-11-29 12:00:59
#include<bits/stdc++.h>
#define M_PI		3.14159265358979323846
using namespace std;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using Complex=pair<double,double>;
#define x first
#define y second
inline const Complex	operator *(const Complex &a,const double &d) {
	return {a.x*d,a.y*d};
}
inline const Complex	operator *(const Complex &a,const Complex &b) {
	return {a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};
}
inline const Complex	operator +(const Complex &a,const Complex &b) {
	return {a.x+b.x,a.y+b.y};
}
inline const Complex	operator -(const Complex &a,const Complex &b) {
	return {a.x-b.x,a.y-b.y};
}

using Comp=Complex;
const int MAX_N=1<<21;//33554432
using uint=unsigned int;
void change(Comp *y,uint len){//nlogn
	for(uint i=1,k,j=len>>1;i<len-1;++i){
		if(i<j)swap(y[i],y[j]);
		k=len>>1;
		while(j>=k){
			j=j-k;
			k=k>>1;
		}
		if(j<k)j+=k;
	}
}
void DFT(Comp *f,const uint n){
	change(f,n);
	const double M_PI2=2*M_PI;
	double hd=M_PI2*0.5;
	for(uint h=2;h<=n;h<<=1,hd*=0.5){
		const uint h2=h>>1;
		Comp wn(cos(hd),sin(hd)),w;
		for(uint j=0;j<n;j+=h){
			w.x=1,w.y=0;
			for(uint k=j;k<j+h2;++k){
				Comp u=f[k],t=w*f[k+h2];
				f[k+h2]=u-t;
				f[k]=u+t;
				w=w*wn;
			}
		}
	}
	return ;
} 
void IDFT(Comp *f,const uint n){
	change(f,n);
	const double M_PI2=2*M_PI;
	double hd=M_PI2*0.5;
	for(uint h=2;h<=n;h<<=1,hd*=0.5){
		const uint h2=h>>1;
		Comp wn(cos(hd),sin(-hd)),w;
		for(uint j=0;j<n;j+=h){
			w.x=1,w.y=0;
			for(uint k=j;k<j+h2;++k){
				Comp u=f[k],t=w*f[k+h2];
				f[k]=u+t;
				f[k+h2]=u-t;
				w=w*wn;
			}
		}
	}
	return ;
} 
Comp a[MAX_N],b[MAX_N];
//uint n,m;
inline int iread(){//not solve LLONG_MIN LMAX=9,223,372,036,854,775,807
    int s=0;char ch=getchar();
    while(ch<'0'||ch>'9'){ch=getchar();}
    while(ch>='0' && ch<='9')s=s*10+ch-'0',ch=getchar();
    return s;
}
unsigned av[3000000];
unsigned bv[3000000];
void poly_multiply(unsigned *ax, int n, unsigned *bx, int m, unsigned *c)
{
	n++,m++;
	for(uint i=0;i<n;++i){
		a[i].x=iread();
	}
	for(uint i=0;i<m;++i){
		b[i].x=iread();
	}
	uint len=1;
	while(len<(n*2)||len<(m*2))len*=2;
	DFT(a,len);
	DFT(b,len);
	for(uint i=0;i<len;++i)
	a[i]=a[i]*b[i];
	IDFT(a,len);
	const double ilen=1.0/len; 
	for(uint i=0;i<n+m-1;++i)
	c[i]=int(a[i].x*ilen+0.5);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #15 s36 KBTime Limit ExceededScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-18 05:37:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠