結果

問題 No.1307 Rotate and Accumulate
ユーザー WizistWizist
提出日時 2020-12-06 00:00:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,024 ms / 5,000 ms
コード長 1,546 bytes
コンパイル時間 1,032 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 120,644 KB
最終ジャッジ日時 2023-10-14 10:51:04
合計ジャッジ時間 12,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,384 KB
testcase_01 AC 66 ms
71,212 KB
testcase_02 AC 65 ms
71,112 KB
testcase_03 AC 89 ms
76,376 KB
testcase_04 AC 83 ms
76,180 KB
testcase_05 AC 75 ms
76,264 KB
testcase_06 AC 74 ms
76,092 KB
testcase_07 AC 67 ms
71,232 KB
testcase_08 AC 533 ms
97,516 KB
testcase_09 AC 525 ms
100,544 KB
testcase_10 AC 539 ms
100,596 KB
testcase_11 AC 520 ms
92,492 KB
testcase_12 AC 549 ms
100,132 KB
testcase_13 AC 157 ms
89,176 KB
testcase_14 AC 315 ms
90,908 KB
testcase_15 AC 1,021 ms
120,512 KB
testcase_16 AC 1,010 ms
119,920 KB
testcase_17 AC 1,015 ms
120,028 KB
testcase_18 AC 1,014 ms
116,568 KB
testcase_19 AC 1,024 ms
120,408 KB
testcase_20 AC 1,022 ms
120,644 KB
testcase_21 AC 67 ms
71,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
#
# No.1307 Rotate and Accumulate
#
import sys, os, math

def ntt(a, inverse=False, mod=998244353, root=3):
	n = 1
	while n < len(a): n <<= 1
	if len(a) < n: a += [0] * (n - len(a))
	r = [0] * 32
	for i in range(len(r)):
		r[i] = mod - pow(root, (mod - 1) >> (i + 2), mod)
	if not inverse:
		k = n >> 1
		while k != 0:
			w = 1
			for s in range(0, n, 2 * k):
				for i in range(s, s + k):
					u = a[i]; v = a[i + k] * w % mod
					a[i] = (u + v) % mod
					a[i + k] = (u - v + mod) % mod
				z = 0; x = s // 2 // k + 1
				while x and x % 2 == 0: z += 1; x >>= 1
				w = w * r[z] % mod
			k >>= 1
	else:
		ir = [0] * len(r)
		for i in range(len(r)): ir[i] = pow(r[i], mod - 2, mod)
		k = 1
		while k < n:
			w = 1
			for s in range(0, n, 2 * k):
				for i in range(s, s + k):
					u = a[i]; v = a[i + k]
					a[i] = (u + v) % mod
					a[i + k] = (u - v + mod) % mod * w % mod
				z = 0; x = s // 2 // k + 1
				while x and x % 2 == 0: z += 1; x >>= 1
				w = w * ir[z] % mod
			k <<= 1
		n_1 = pow(n, mod - 2, mod)
		for i in range(len(a)): a[i] = a[i] * n_1 % mod

def multiply(a, b):
	n = 1
	while n < len(a) + len(b): n <<= 1
	f, g = [0] * n, [0] * n
	for i, v in enumerate(a): f[i] = v
	for i, v in enumerate(b): g[i] = v
	ntt(f); ntt(g)
	for i in range(n): f[i] *= g[i]
	ntt(f, True)
	return f

def read_ints(): return list(map(int, input().split()))

n, q = read_ints()
a, r = read_ints(), read_ints()

f = a + a
g = [0] * (n + 1)
for x in r: g[n - x] += 1

c = multiply(f, g)
print(" ".join(map(str, c[n:n + n])))
0