結果
| 問題 | No.1697 Deque House |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-16 13:57:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,015 ms / 3,500 ms |
| コード長 | 2,508 bytes |
| コンパイル時間 | 228 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 282,648 KB |
| 最終ジャッジ日時 | 2024-07-19 09:47:37 |
| 合計ジャッジ時間 | 16,409 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
mod = 998244353
omega = pow(3,119,mod)
rev_omega = pow(omega,mod-2,mod)
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]
N,K = map(int,input().split())
A = list(map(int,input().split()))
pow_2 = [1] * (N*K+1)
for i in range(1,N*K+1):
pow_2[i] = 2 * pow_2[i-1] % mod
dp = [[0 for j in range(N+1)] for i in range(K+1)]
for j in range(1,N+1):
dp[0][j] = 1
for i in range(1,K+1):
dp[i] = [dp[i-1][j] * pow_2[j-1] % mod for j in range(N+1)]
for j in range(1,N+1):
dp[i][j] += dp[i][j-1]
dp[i][j] %= mod
ans = 0
A_pow = [1 for i in range(N)]
for x in range(K):
F = [0] * (N+1)
G = [0] * (N+1)
for i in range(N):
F[i+1] = dp[x][i+1] * (A_pow[i] + A_pow[-i-1]) % mod
G[i+1] = dp[K-x-1][i+1] * pow_2[(i+1)*x] % mod
H = convolve(F,G,N)
#print(F,G,H)
for s in range(2,N):
ans += dp[K][N-s] * H[s] % mod
ans %= mod
for i in range(N):
A_pow[i] = A_pow[i] * A[i] % mod
for i in range(N):
ans += ((dp[K][i]*dp[K][N-1-i] % mod)*pow_2[K] % mod)*A_pow[i] % mod
ans %= mod
ans += (dp[K-1][i+1]*dp[K][N-1-i] % mod)*A_pow[i] % mod
ans %= mod
ans += (dp[K][i]*dp[K-1][N-i] % mod)*A_pow[i] % mod
ans %= mod
print(ans)