結果
問題 | No.1307 Rotate and Accumulate |
ユーザー | Wizist |
提出日時 | 2020-12-05 22:30:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 959 ms / 5,000 ms |
コード長 | 1,732 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 116,508 KB |
最終ジャッジ日時 | 2024-09-16 04:52:02 |
合計ジャッジ時間 | 10,638 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,088 KB |
testcase_01 | AC | 37 ms
53,056 KB |
testcase_02 | AC | 37 ms
53,204 KB |
testcase_03 | AC | 46 ms
61,960 KB |
testcase_04 | AC | 56 ms
67,708 KB |
testcase_05 | AC | 45 ms
61,952 KB |
testcase_06 | AC | 45 ms
61,560 KB |
testcase_07 | AC | 37 ms
53,732 KB |
testcase_08 | AC | 487 ms
96,816 KB |
testcase_09 | AC | 489 ms
99,468 KB |
testcase_10 | AC | 505 ms
109,680 KB |
testcase_11 | AC | 482 ms
91,440 KB |
testcase_12 | AC | 502 ms
110,200 KB |
testcase_13 | AC | 132 ms
88,120 KB |
testcase_14 | AC | 278 ms
90,352 KB |
testcase_15 | AC | 946 ms
115,328 KB |
testcase_16 | AC | 950 ms
115,336 KB |
testcase_17 | AC | 942 ms
115,272 KB |
testcase_18 | AC | 949 ms
111,980 KB |
testcase_19 | AC | 942 ms
116,508 KB |
testcase_20 | AC | 959 ms
116,412 KB |
testcase_21 | AC | 38 ms
53,796 KB |
ソースコード
#!/usr/bin/env python3 # # No.1307 Rotate and Accumulate # import sys, os, math def ntt(a, inverse=False): mod, root, root_pw = (119 << 23) + 1, 3, 1 << 23 root_1 = pow(root, mod - 2, mod) r = [0] * 30; ir = [0] * 30 for i in range(len(r)): r[i] = mod - pow(root, (mod - 1) >> (i + 2), mod) ir[i] = pow(r[i], mod - 2, mod) n = 1 while n < len(a): n <<= 1 if len(a) < n: a += [0] * (n - len(a)) if not inverse: k = n >> 1 while k != 0: w = 1 wk = root; i = k while i < root_pw: wk = wk * wk % mod; i <<= 1 t = 0 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 t += 1 z = 0; x = t while x and x % 2 == 0: z += 1; x >>= 1 w = w * r[z] % mod k >>= 1 else: k = 1 while k < n: w = 1 wk = root_1; i = k while i < root_pw: wk = wk * wk % mod; i <<= 1 t = 0 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 t += 1 z = 0; x = t 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])))