提交记录 8245


用户 题目 状态 得分 用时 内存 语言 代码长度
Conical 1002i. 【模板题】多项式乘法 Accepted 100 52.638 ms 18228 KB C++ 1.70 KB
提交时间 评测时间
2019-02-05 21:00:11 2020-08-01 01:14:33
#include <bits/stdc++.h>
using namespace std;

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

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

void dft(comp_t *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_t wn(cos(pi / l), sin(pi / l) * f);
		static comp_t 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_t x = a[i + j], y = a[i + j + l] * w[j];
				a[i + j] = x + y, a[i + j + l] = x - y;
			}
	}
}

int main()
{
	int n, m, L, k;
	scanf("%d%d", &n, &m);
	for(int i = 0; i <= n; i++)
		scanf("%lf", &A[i].x);
	for(int i = 0; i <= m; i++)
		scanf("%lf", &A[i].y);
	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);
	A[L] = A[0];
	for(int i = 0; i <= L - i; i++)
	{
		comp_t t1 = (A[i] + A[L - i].conj()) * comp_t(0, 1) * (A[i] - A[L - i].conj());
		comp_t t2 = (A[L - i] + A[i].conj()) * comp_t(0, 1) * (A[L - i] - A[i].conj());
		t1 /= 4, t2 /= 4;
		A[i] = t1, A[L - i] = t2;
	}
	dft(A, L, -1);
	for(int i = 0; i <= n + m; i++)
		printf("%d ", (int) (-A[i].x / L + 0.5));
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.736 ms15 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #252.638 ms17 MB + 740 KBAcceptedScore: 100

Subtask #1 Testcase #325.217 ms16 MB + 80 KBAcceptedScore: 0

Subtask #1 Testcase #425.21 ms16 MB + 68 KBAcceptedScore: 0

Subtask #1 Testcase #51.811 ms15 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #61.808 ms15 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #71.806 ms15 MB + 312 KBAcceptedScore: 0

Subtask #1 Testcase #846.493 ms17 MB + 472 KBAcceptedScore: 0

Subtask #1 Testcase #946.276 ms17 MB + 472 KBAcceptedScore: 0

Subtask #1 Testcase #1040.274 ms17 MB + 204 KBAcceptedScore: 0

Subtask #1 Testcase #1152.622 ms17 MB + 820 KBAcceptedScore: 0

Subtask #1 Testcase #1252.593 ms16 MB + 700 KBAcceptedScore: 0

Subtask #1 Testcase #13896.87 us7 MB + 692 KBAcceptedScore: 0


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