提交记录 8341


用户 题目 状态 得分 用时 内存 语言 代码长度
xgzc 1002i. 【模板题】多项式乘法 Accepted 100 60.788 ms 10776 KB C++ 1.87 KB
提交时间 评测时间
2019-02-13 09:05:40 2020-08-01 01:17:05
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x))

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while(ch != '-' && (!isdigit(ch))) ch = getchar();
	if(ch == '-') w = -1, ch = getchar();
	while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int maxn(3e6 + 10);
const double pi(acos(-1));
struct complex { double x, y; } a[maxn], b[maxn];
inline complex operator + (const complex &lhs, const complex &rhs)
	{ return (complex) {lhs.x + rhs.x, lhs.y + rhs.y}; };
inline complex operator - (const complex &lhs, const complex &rhs)
	{ return (complex) {lhs.x - rhs.x, lhs.y - rhs.y}; };
inline complex operator * (const complex &lhs, const complex &rhs)
{
	return (complex) {lhs.x * rhs.x - lhs.y * rhs.y,
		lhs.y * rhs.x + lhs.x * rhs.y};
}

int n, m, r[maxn], P;
template<int opt> void FFT(complex *p)
{
	for(RG int i = 0; i < n; i++) if(i < r[i]) std::swap(p[i], p[r[i]]);
	for(RG int i = 1; i < n; i <<= 1)
	{
		complex rot = (complex) {cos(pi / i), opt * sin(pi / i)};
		for(RG int j = 0; j < n; j += (i << 1))
		{
			complex w = (complex) {1, 0};
			for(RG int k = 0; k < i; ++k, w = w * rot)
			{
				complex x = p[j + k], y = w * p[i + j + k];
				p[j + k] = x + y, p[i + j + k] = x - y;
			}
		}
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(), m = read();
	for(RG int i = 0; i <= n; i++) a[i].x = read();
	for(RG int i = 0; i <= m; i++) b[i].x = read();
	for(m += n, n = 1; n <= m; n <<= 1, ++P);
	for(RG int i = 0; i < n; i++)
		r[i] = (r[i >> 1] >> 1) | ((i & 1) << (P - 1));
	FFT<1>(a), FFT<1>(b);
	for(RG int i = 0; i < n; i++) a[i] = a[i] * b[i];
	FFT<-1>(a);
	for(RG int i = 0; i <= m; i++) printf("%d ", (int)(a[i].x / n + .5));
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #110 us28 KBAcceptedScore: 0

Subtask #1 Testcase #260.453 ms10 MB + 456 KBAcceptedScore: 100

Subtask #1 Testcase #327.284 ms4 MB + 820 KBAcceptedScore: 0

Subtask #1 Testcase #427.355 ms4 MB + 808 KBAcceptedScore: 0

Subtask #1 Testcase #511.42 us28 KBAcceptedScore: 0

Subtask #1 Testcase #610.34 us28 KBAcceptedScore: 0

Subtask #1 Testcase #710.13 us28 KBAcceptedScore: 0

Subtask #1 Testcase #855.138 ms10 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #955.133 ms10 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1049.844 ms9 MB + 944 KBAcceptedScore: 0

Subtask #1 Testcase #1160.788 ms10 MB + 536 KBAcceptedScore: 0

Subtask #1 Testcase #1260.562 ms9 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #138.99 us28 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-20 22:48:34 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用