結果
問題 | No.1697 Deque House |
ユーザー | ygussany |
提出日時 | 2021-09-29 09:46:23 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 587 ms / 3,500 ms |
コード長 | 3,473 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 34,432 KB |
実行使用メモリ | 34,944 KB |
最終ジャッジ日時 | 2024-07-19 10:18:01 |
合計ジャッジ時間 | 4,837 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 556 ms
34,944 KB |
testcase_10 | AC | 75 ms
14,592 KB |
testcase_11 | AC | 110 ms
16,000 KB |
testcase_12 | AC | 69 ms
13,824 KB |
testcase_13 | AC | 68 ms
7,808 KB |
testcase_14 | AC | 122 ms
11,776 KB |
testcase_15 | AC | 321 ms
22,272 KB |
testcase_16 | AC | 219 ms
19,968 KB |
testcase_17 | AC | 208 ms
13,184 KB |
testcase_18 | AC | 76 ms
10,752 KB |
testcase_19 | AC | 196 ms
13,696 KB |
testcase_20 | AC | 561 ms
34,944 KB |
testcase_21 | AC | 587 ms
34,816 KB |
testcase_22 | AC | 569 ms
34,816 KB |
ソースコード
#include <stdio.h> const int Mod = 998244353, bit[19] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144}, bit_inv[19] = {1, 499122177, 748683265, 873463809, 935854081, 967049217, 982646785, 990445569, 994344961, 996294657, 997269505, 997756929, 998000641, 998122497, 998183425, 998213889, 998229121, 998236737, 998240545}, root[19] = {1, 998244352, 911660635, 372528824, 929031873, 452798380, 922799308, 781712469, 476477967, 166035806, 258648936, 584193783, 63912897, 350007156, 666702199, 968855178, 629671588, 24514907, 996173970}, root_inv[19] = {1, 998244352, 86583718, 509520358, 337190230, 87557064, 609441965, 135236158, 304459705, 685443576, 381598368, 335559352, 129292727, 358024708, 814576206, 708402881, 283043518, 3707709, 121392023}; int ntt_b[19][262144], ntt_c[19][262144], ntt_x[19][262144], ntt_y[19][262144]; void NTT(int k, int a[], int z[]) { if (k == 0) { z[0] = a[0]; return; } int i, d = bit[k-1], tmpp; long long tmp; for (i = 0; i < d; i++) { ntt_b[k][i] = a[i*2]; ntt_c[k][i] = a[i*2+1]; } NTT(k - 1, ntt_b[k], ntt_x[k]); NTT(k - 1, ntt_c[k], ntt_y[k]); for (i = 0, tmp = 1; i < d; i++, tmp = tmp * root[k] % Mod) { tmpp = tmp * ntt_y[k][i] % Mod; z[i] = ntt_x[k][i] + tmpp; if (z[i] >= Mod) z[i] -= Mod; z[i+d] = ntt_x[k][i] - tmpp; if (z[i+d] < 0) z[i+d] += Mod; } } void NTT_reverse(int k, int z[], int a[]) { if (k == 0) { a[0] = z[0]; return; } int i, d = bit[k-1], tmpp; long long tmp; for (i = 0; i < d; i++) { ntt_x[k][i] = z[i*2]; ntt_y[k][i] = z[i*2+1]; } NTT_reverse(k - 1, ntt_x[k], ntt_b[k]); NTT_reverse(k - 1, ntt_y[k], ntt_c[k]); for (i = 0, tmp = 1; i < d; i++, tmp = tmp * root_inv[k] % Mod) { tmpp = tmp * ntt_c[k][i] % Mod; a[i] = ntt_b[k][i] + tmpp; if (a[i] >= Mod) a[i] -= Mod; a[i+d] = ntt_b[k][i] - tmpp; if (a[i+d] < 0) a[i+d] += Mod; } } int main() { int i, N, K, A[100001]; scanf("%d %d", &N, &K); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); int j, k, dp[2][15][100001]; long long pow[1400001]; for (i = 1, pow[0] = 1; i <= N * K; i++) pow[i] = pow[i-1] * 2 % Mod; for (j = 1; j <= N; j++) { dp[0][0][j] = 1; dp[1][0][j] = (j == 1)? 1: 0; } for (k = 1; k <= K; k++) { dp[0][k][1] = 1; dp[1][k][1] = 1; for (j = 2; j <= N; j++) { dp[0][k][j] = dp[0][k][j-1] + dp[0][k-1][j] * pow[j-1] % Mod; if (dp[0][k][j] >= Mod) dp[0][k][j] -= Mod; dp[1][k][j] = dp[1][k][j-1] + dp[1][k-1][j] * pow[j-1] % Mod; if (dp[1][k][j] >= Mod) dp[1][k][j] -= Mod; } } int a[262144], b[262144], c[262144], x[262144], y[262144], z[262144]; long long ans = 0, tmp[100001]; for (j = 1; j <= N; j++) tmp[j] = 1; for (i = 0; bit[i] < N * 2 + 1; i++); for (j = 1, a[0] = 0; j <= N; j++) a[j] = dp[0][K][j]; NTT(i, a, x); for (k = 0; k < K; k++) { for (j = 1, b[0] = 0; j <= N; j++) b[j] = dp[1][K-k][j] * pow[k*j] % Mod; NTT(i, b, y); for (j = 0; j < bit[i]; j++) z[j] = (long long)x[j] * y[j] % Mod; NTT_reverse(i, z, c); for (j = 0; j <= N; j++) c[j] = (long long)c[j] * bit_inv[i] % Mod; for (j = 1; j <= N; j++) { ans += tmp[j] * (((long long)dp[0][k][j] * c[N-j] + (long long)dp[0][k][N-j+1] * c[j-1]) % Mod) % Mod; tmp[j] = tmp[j] * A[j] % Mod; } } for (j = 1; j <= N; j++) ans += tmp[j] * (((long long)dp[0][K][j-1] * dp[0][K][N-j+1] + (long long)dp[1][K][j] * dp[0][K][N-j]) % Mod) % Mod; printf("%lld\n", ans % Mod); fflush(stdout); return 0; }