提交记录 10241


用户 题目 状态 得分 用时 内存 语言 代码长度
CraZYali 1002i. 【模板题】多项式乘法 Accepted 100 48.562 ms 5032 KB C++ 2.55 KB
提交时间 评测时间
2019-09-06 21:45:34 2020-08-01 02:04:41
#define DREP(i, s, e) for(int i(s), end_##i(e); i >= end_##i ;i--)
#define  REP(i, s, e) for(int i(s), end_##i(e); i <= end_##i ;i++)

#define DEBUG fprintf(stderr, "Passing [%s] in Line %d\n", __FUNCTION__, __LINE__)
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)

#include <iostream>
#include <cstdio>
using namespace std;
const int maxlen = (1e5 + 1e5 + 10) * 2;
const int MOD = 998244353, gg = 3;
//const int MOD = 469762049, gg = 7;

char buf[maxlen + 5], *p = buf;
#define Getchar() (*p++)

int power_pow(long long base, int b)
{
	long long ans(1);
	while (b)
	{
		if (b & 1) (ans *= base) %= MOD;
		(base *= base) %= MOD;
		b >>= 1;
	}
	return ans;
}
#define inv(x) power_pow(x, MOD - 2)

int n, m, k;

inline void write(const int x) {if (x / 10) write(x / 10);putchar(x % 10 + '0');}

int L, len, *R, *f, *g;
inline void NTT(int a[], int flag)
{
	REP(i, 1, len - 1)
		if (i < R[i]) swap(a[i], a[R[i]]);
	if (flag > 0)
		for (register int i = 1; i < len; i <<= 1)
		{
			const int wn = power_pow(gg, (MOD - 1) / (i << 1));
			for (register int k = 0; k < len; k += i << 1)
			{
				long long w(1);
				for (register int l(0); l < i; l++, (w *= wn) %= MOD)
				{
					const register int x(a[k + l]), y(w * a[k + l + i] % MOD);
					a[k + l] = (x + y) % MOD;
					a[k + l + i] = (x - y) % MOD;
				}
			}
		}
	else
		for (register int i = 1; i < len; i <<= 1)
		{
			const int wn = inv(power_pow(gg, (MOD - 1) / (i << 1)));
			for (register int k = 0; k < len; k += i << 1)
			{
				long long w(1);
				for (register int l(0); l < i; l++, (w *= wn) %= MOD)
				{
					const register int x(a[k + l]), y(w * a[k + l + i] % MOD);
					a[k + l] = (x + y) % MOD;
					a[k + l + i] = (x - y) % MOD;
				}
			}
		}
	if (flag < 0)
	{
		static const int invN = inv(len);
		REP(i, 0, len - 1) a[i] = 1ll * a[i] * invN % MOD;
	}
}

signed main()
{
#ifdef CraZYali
	freopen("NTT.in", "r", stdin);
	freopen("NTT.out", "w", stdout);
#endif
	fread(buf, 1, maxlen, stdin);
	char c;
	while (isdigit(c = Getchar())) n = n * 10 + c - 48;
	while (isdigit(c = Getchar())) m = m * 10 + c - 48;
	L = 1;
	while ((1 << L) <= n + m) L++;
	len = 1 << L;
	R = new int[len];R[0] = 0;
	f = new int[len];
	g = new int[len];
	REP(i, 1, len - 1) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L-1);
	REP(i, 0, n) f[i] = Getchar() ^ 48, Getchar();
	REP(i, 0, m) g[i] = Getchar() ^ 48, Getchar();
	REP(i, n + 1, len - 1) f[i] = 0 ;
	REP(i, m + 1, len - 1) g[i] = 0 ;
	NTT(f, 1);NTT(g, 1);
	REP(i, 0, len-1) f[i] = 1ll * f[i] * g[i] % MOD;
	NTT(f, -1);
	REP(i, 0, n + m) write((f[i] + MOD) % MOD), putchar(' ');
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #135.29 us40 KBAcceptedScore: 0

Subtask #1 Testcase #247.37 ms4 MB + 856 KBAcceptedScore: 100

Subtask #1 Testcase #319.708 ms2 MB + 4 KBAcceptedScore: 0

Subtask #1 Testcase #419.8 ms1 MB + 1016 KBAcceptedScore: 0

Subtask #1 Testcase #538.58 us40 KBAcceptedScore: 0

Subtask #1 Testcase #637.61 us40 KBAcceptedScore: 0

Subtask #1 Testcase #736.07 us40 KBAcceptedScore: 0

Subtask #1 Testcase #845.579 ms4 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #945.551 ms4 MB + 524 KBAcceptedScore: 0

Subtask #1 Testcase #1043.771 ms4 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1148.562 ms4 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1239.745 ms3 MB + 816 KBAcceptedScore: 0

Subtask #1 Testcase #1335.62 us40 KBAcceptedScore: 0


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