提交记录 7900


用户 题目 状态 得分 用时 内存 语言 代码长度
Conical 1002i. 【模板题】多项式乘法 Accepted 100 61.67 ms 26044 KB C++ 1.42 KB
提交时间 评测时间
2019-01-25 19:37:02 2020-08-01 01:10:06
#include <bits/stdc++.h>
using namespace std;

const double pi (acos(-1));
const int MaxN(500003);
int rev[MaxN];

struct comp
{
	double x, y;
	comp(double _x = 0, double _y = 0) : x(_x), y(_y) { }
	inline comp operator + (const comp &T)
	{ return comp(x + T.x, y + T.y); }
	inline comp operator - (const comp &T)
	{ return comp(x - T.x, y - T.y); }
	inline comp operator * (const comp &T)
	{ return comp(x * T.x - y * T.y, x * T.y + y * T.x); }
}A[MaxN], B[MaxN];

void dft(comp *a, int n, int f)
{
	for(int i = 1; i < n; i++)
		if(i < rev[i])
			swap(a[i], a[rev[i]]);
	for(int l = 1; l < n; l <<= 1)
	{
		comp wn(cos(pi / l), sin(pi / l) * f);
		static comp w[MaxN];
		w[0] = 1.0;
		for(int i = 1; i < l; i++)
			w[i] = w[i - 1] * wn;
		for(int i = 0; i < n; i += l << 1)
			for(int j = 0; j < l; j++)
			{
				comp x = a[i + j], y = a[i + j + l] * w[j];
				a[i + j] = x + y, a[i + j + l] = x - y;
			}
	}
	if(f == -1)
		for(int i = 0; i < n; i++)
			a[i].x /= n;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	++n, ++m;
	for(int i = 0; i < n; i++)
		scanf("%lf", &A[i].x);
	for(int i = 0; i < m; i++)
		scanf("%lf", &B[i].x);
	int L, k;
	for(L = 1, k = -1; L < n + m; L <<= 1, ++k);
	for(int i = 1; i < L; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << k);
	dft(A, L, 1), dft(B, L, 1);
	for(int i = 0; i < L; i++)
		A[i] = A[i] * B[i];
	dft(A, L, -1);
	for(int i = 0; i < n + m - 1; i++)
		printf("%d ", (int) (A[i].x + 0.5));
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #12.701 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #261.67 ms25 MB + 364 KBAcceptedScore: 100

Subtask #1 Testcase #329.402 ms23 MB + 728 KBAcceptedScore: 0

Subtask #1 Testcase #429.384 ms23 MB + 716 KBAcceptedScore: 0

Subtask #1 Testcase #52.595 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #62.597 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #72.585 ms22 MB + 960 KBAcceptedScore: 0

Subtask #1 Testcase #855.511 ms25 MB + 96 KBAcceptedScore: 0

Subtask #1 Testcase #955.408 ms25 MB + 96 KBAcceptedScore: 0

Subtask #1 Testcase #1049.418 ms24 MB + 852 KBAcceptedScore: 0

Subtask #1 Testcase #1161.662 ms25 MB + 444 KBAcceptedScore: 0

Subtask #1 Testcase #1261.508 ms24 MB + 324 KBAcceptedScore: 0

Subtask #1 Testcase #132.578 ms22 MB + 960 KBAcceptedScore: 0


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