結果
問題 | No.1697 Deque House |
ユーザー | chineristAC |
提出日時 | 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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,864 KB |
testcase_01 | AC | 43 ms
53,632 KB |
testcase_02 | AC | 44 ms
53,120 KB |
testcase_03 | AC | 42 ms
52,608 KB |
testcase_04 | AC | 44 ms
53,888 KB |
testcase_05 | AC | 42 ms
52,864 KB |
testcase_06 | AC | 65 ms
66,944 KB |
testcase_07 | AC | 93 ms
76,444 KB |
testcase_08 | AC | 94 ms
76,544 KB |
testcase_09 | AC | 2,006 ms
280,216 KB |
testcase_10 | AC | 293 ms
152,080 KB |
testcase_11 | AC | 455 ms
190,380 KB |
testcase_12 | AC | 297 ms
150,360 KB |
testcase_13 | AC | 394 ms
148,784 KB |
testcase_14 | AC | 594 ms
189,876 KB |
testcase_15 | AC | 1,362 ms
279,228 KB |
testcase_16 | AC | 930 ms
267,964 KB |
testcase_17 | AC | 956 ms
263,628 KB |
testcase_18 | AC | 381 ms
160,996 KB |
testcase_19 | AC | 892 ms
264,676 KB |
testcase_20 | AC | 2,015 ms
280,344 KB |
testcase_21 | AC | 1,994 ms
282,520 KB |
testcase_22 | AC | 1,983 ms
282,648 KB |
ソースコード
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)