結果

問題 No.1697 Deque House
ユーザー chineristACchineristAC
提出日時 2021-08-16 13:57:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,928 ms / 3,500 ms
コード長 2,508 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 276,428 KB
最終ジャッジ日時 2023-09-26 15:42:27
合計ジャッジ時間 16,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,236 KB
testcase_01 AC 76 ms
71,308 KB
testcase_02 AC 73 ms
71,096 KB
testcase_03 AC 71 ms
71,220 KB
testcase_04 AC 73 ms
71,396 KB
testcase_05 AC 69 ms
71,108 KB
testcase_06 AC 87 ms
76,604 KB
testcase_07 AC 116 ms
77,784 KB
testcase_08 AC 112 ms
77,700 KB
testcase_09 AC 1,925 ms
275,212 KB
testcase_10 AC 305 ms
146,344 KB
testcase_11 AC 426 ms
180,756 KB
testcase_12 AC 286 ms
152,256 KB
testcase_13 AC 403 ms
154,832 KB
testcase_14 AC 589 ms
202,560 KB
testcase_15 AC 1,288 ms
276,428 KB
testcase_16 AC 912 ms
269,856 KB
testcase_17 AC 929 ms
264,652 KB
testcase_18 AC 383 ms
162,144 KB
testcase_19 AC 871 ms
265,788 KB
testcase_20 AC 1,928 ms
275,736 KB
testcase_21 AC 1,925 ms
275,840 KB
testcase_22 AC 1,918 ms
275,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

0