結果
問題 | No.1839 Concatenation Matrix |
ユーザー | chineristAC |
提出日時 | 2022-02-11 23:19:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,605 ms / 3,500 ms |
コード長 | 3,000 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 334,628 KB |
最終ジャッジ日時 | 2024-06-27 21:41:42 |
合計ジャッジ時間 | 21,227 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
mod = 998244353 omega = pow(3,119,mod) rev_omega = pow(omega,mod-2,mod) N = 2*10**5 g1 = [1]*(N+1) # 元テーブル g2 = [1]*(N+1) #逆元テーブル inv = [1]*(N+1) #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inv[i]=( ( -inv[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inv[i]) % mod ) inv[0]=0 def _ntt(f,L,reverse=False): F=[f[i] for i in range(L)] n = L.bit_length() - 1 base = omega if reverse: base = rev_omega if not n: return F size = 2**n wj = pow(base,2**22,mod) res = [0]*2**n for i in range(n,0,-1): use_omega = pow(base,2**(22+i-n),mod) res = [0]*2**n size //= 2 w = 1 for j in range(0,L//2,size): for a in range(size): res[a+j] = (F[a+2*j] + w * F[a+size+2*j]) % mod t = (w * wj) % mod res[L//2+a+j] = (F[a+2*j] + t * F[a+size+2*j]) % mod w = (w * use_omega) % mod F = res return res def ntt(f,L=0): l = len(f) if not L: L = 1<<((l-1).bit_length()) while len(f)<L: f.append(0) f=f[:L] F = _ntt(f,L) return F def intt(f,L=0): l = len(f) if not L: L = 1<<((l-1).bit_length()) while len(f)<L: f.append(0) f=f[:L] F = _ntt(f,L,reverse=True) inv = pow(L,mod-2,mod) for i in range(L): F[i] *= inv F[i] %= mod return F def convolve(f,g,limit): l = len(f)+len(g)-1 L = 1<<((l-1).bit_length()) F = ntt(f,L) G = ntt(g,L) H = [(F[i] * G[i]) % mod for i in range(L)] h = intt(H,L) return h[:limit] class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.size = n for i in range(n): self.tree[self.num + i] = init_val[i] for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def merge(f,g): return convolve(f,g,len(f)+len(g)) N = int(input()) A = li() i10 = inv[10] init = [] tmp = i10 for i in range(N-1): init.append([1,tmp]) tmp = tmp * tmp % mod seg = SegmentTree(init,merge,[1]) last = seg.tree[1] t = 10 for i in range(N-1): t = t * t % mod for i in range(N): last[i] = (last[i] * (t*i10 % mod)) % mod last = [last[0]] + [last[i] for i in range(1,N)[::-1]] final = convolve(A,last,3*N) for i in range(N,len(final)): final[i%N] += final[i] final[i%N] %= mod print(*final[:N],sep="\n")