提交记录 8967


用户 题目 状态 得分 用时 内存 语言 代码长度
YeahPotato 1002i. 【模板题】多项式乘法 Accepted 100 38.96 ms 11972 KB C++ 2.05 KB
提交时间 评测时间
2019-03-26 19:41:36 2020-08-01 01:28:04
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const double Pi = acos(-1.0);
const int N = 3e5+5;
int n, m, f[N], len = 1, lim;
struct Complex {
	double a, b;
	Complex (double _a = 0, double _b = 0) { a = _a, b = _b; }
} a[N], b[N], Omega[30];
Complex operator + (const Complex &x, const Complex &y) {
	return Complex(x. a + y. a, x. b + y. b); }
Complex operator - (const Complex &x, const Complex &y) {
	return Complex(x. a - y. a, x. b - y. b); }
Complex operator * (const Complex &x, const Complex &y) {
	return Complex(x. a * y. a - x. b * y. b, x. b * y. a + x. a * y. b); }
inline Complex Conj(Complex z) {
	return Complex(z. a, -z. b);
}
inline int read() {
	int s=0, w=1;
	char ch=getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-') w = -w;
		ch=getchar();
	}
	while (ch>='0' && ch<='9')
		s = s*10 + ch-'0', ch=getchar();
	return s*w;
}
void write1(int x) {
	if (x < 0) putchar (45), x = -x;
	if (x > 9) write1(x / 10);
	putchar(x % 10 + 48);
}
void FFT(Complex *a, int n, bool op) {
	for (int i=0; i<n; i++)
		if (i < f[i]) swap(a[i], a[f[i]]);
	for (int m=1, t=0; m<n; m<<=1, t++) {
		Complex omega = op ? Conj(Omega[t]) : Omega[t];
		for (int i=0; i<n; i+=m<<1) {
			Complex x = Complex(1, 0);
			for (int j=0; j<m; j++, x=x*omega) {
				Complex tmp = x * a[i + j + m];
				a[i + j + m] = a[i + j] - tmp;
				a[i + j] = a[i + j] + tmp;
			}
		}
	}
}
int main() {
	cin >> n >> m;
	for (int i=0; i<=n; i++)
		a[i]. a = read();
	for (int i=0; i<=m; i++)
		b[i]. a = read();
	n += m;
	while (len <= n) ++lim, len <<= 1;
	Omega[lim] = Complex(cos(Pi / len), sin(Pi / len));
	for (int i=lim-1; ~i; i--)
		Omega[i] = Omega[i+1] * Omega[i+1];
/*	Omega[0] = Complex(1, 0), 
	Omega[1] = Complex(cos(2 * Pi / len), sin(2 * Pi / len));
	for (int i=2; i<len; i++)
		Omega[i] = Omega[i-1] * Omega[1]; */
	for (int i=0; i<len; i++)
		f[i] = f[i >> 1] >> 1 | (i & 1) << lim - 1;
	FFT(a, len, 0), FFT(b, len, 0);
	for (int i=0; i<len; i++)
		a[i] = a[i] * b[i];
	FFT(a, len, 1);
	for (int i=0; i<=n; i++)
		write1((int) (a[i]. a / len + 0.5)), putchar (' ');
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #11.068 ms9 MB + 200 KBAcceptedScore: 0

Subtask #1 Testcase #238.755 ms11 MB + 628 KBAcceptedScore: 100

Subtask #1 Testcase #316.506 ms9 MB + 992 KBAcceptedScore: 0

Subtask #1 Testcase #416.596 ms9 MB + 980 KBAcceptedScore: 0

Subtask #1 Testcase #51.051 ms9 MB + 200 KBAcceptedScore: 0

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

Subtask #1 Testcase #71.045 ms9 MB + 200 KBAcceptedScore: 0

Subtask #1 Testcase #837.727 ms11 MB + 360 KBAcceptedScore: 0

Subtask #1 Testcase #937.739 ms11 MB + 360 KBAcceptedScore: 0

Subtask #1 Testcase #1036.758 ms11 MB + 92 KBAcceptedScore: 0

Subtask #1 Testcase #1138.96 ms11 MB + 708 KBAcceptedScore: 0

Subtask #1 Testcase #1234.977 ms10 MB + 588 KBAcceptedScore: 0

Subtask #1 Testcase #131.076 ms9 MB + 200 KBAcceptedScore: 0


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