結果
問題 | No.2215 Slide Subset Sum |
ユーザー | 👑 ygussany |
提出日時 | 2023-02-05 13:58:17 |
言語 | C (gcc 12.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,000 bytes |
コンパイル時間 | 338 ms |
コンパイル使用メモリ | 34,520 KB |
実行使用メモリ | 87,836 KB |
最終ジャッジ日時 | 2024-07-04 06:48:31 |
合計ジャッジ時間 | 5,669 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 171 ms
82,176 KB |
testcase_01 | TLE | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
ソースコード
#include <stdio.h> const int Mod = 998244353, bit[21] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576}, bit_inv[21] = {1, 499122177, 748683265, 873463809, 935854081, 967049217, 982646785, 990445569, 994344961, 996294657, 997269505, 997756929, 998000641, 998122497, 998183425, 998213889, 998229121, 998236737, 998240545, 998242449, 998243401}, root[21] = {1, 998244352, 911660635, 372528824, 929031873, 452798380, 922799308, 781712469, 476477967, 166035806, 258648936, 584193783, 63912897, 350007156, 666702199, 968855178, 629671588, 24514907, 996173970, 363395222, 565042129}, root_inv[21] = {1, 998244352, 86583718, 509520358, 337190230, 87557064, 609441965, 135236158, 304459705, 685443576, 381598368, 335559352, 129292727, 358024708, 814576206, 708402881, 283043518, 3707709, 121392023, 704923114, 950391366}; void NTT_inline(int kk, int a[], int x[]) { int h, hh, i, ii, j, jj, k, l, r = bit[kk], d = bit[kk-1], tmpp, cur, prev; int *pi, *pii, *pj, *pjj; static int y[2][256]; long long tmp; for (i = 0; i < r; i++) y[0][i] = a[i]; for (k = 1, kk--, cur = 1, prev = 0; kk >= 0; k++, kk--, cur ^= 1, prev ^= 1) { for (h = 0, tmp = 1; h << (kk + 1) < r; h++, tmp = tmp * root[k] % Mod) { for (hh = 0, pi = &(y[cur][h<<kk]), pii = pi + d, pj = &(y[prev][h<<(kk+1)]), pjj = pj + bit[kk]; hh < bit[kk]; hh++, pi++, pii++, pj++, pjj++) { tmpp = tmp * (*pjj) % Mod; *pi = *pj + tmpp; if (*pi >= Mod) *pi -= Mod; *pii = *pj - tmpp; if (*pii < 0) *pii += Mod; } } } for (i = 0; i < r; i++) x[i] = y[prev][i]; } void NTT_reverse_inline(int kk, int a[], int x[]) { int h, hh, i, ii, j, jj, k, l, r = bit[kk], d = bit[kk-1], tmpp, cur, prev; int *pi, *pii, *pj, *pjj; static int y[2][256]; long long tmp; for (i = 0; i < r; i++) y[0][i] = a[i]; for (k = 1, kk--, cur = 1, prev = 0; kk >= 0; k++, kk--, cur ^= 1, prev ^= 1) { for (h = 0, tmp = 1; h << (kk + 1) < r; h++, tmp = tmp * root_inv[k] % Mod) { for (hh = 0, pi = &(y[cur][h<<kk]), pii = pi + d, pj = &(y[prev][h<<(kk+1)]), pjj = pj + bit[kk]; hh < bit[kk]; hh++, pi++, pii++, pj++, pjj++) { tmpp = tmp * (*pjj) % Mod; *pi = *pj + tmpp; if (*pi >= Mod) *pi -= Mod; *pii = *pj - tmpp; if (*pii < 0) *pii += Mod; } } } for (i = 0; i < r; i++) x[i] = y[prev][i]; } // Compute the product of two polynomials a[0-da] and b[0-db] using NTT in O(d * log d) time void prod_poly_NTT(int da, int db, int a[], int b[], int c[]) { int i, k; static int aa[256], bb[256], cc[256]; for (k = 0; bit[k] <= da + db; k++); for (i = 0; i <= da; i++) aa[i] = a[i]; for (i = da + 1; i < bit[k]; i++) aa[i] = 0; for (i = 0; i <= db; i++) bb[i] = b[i]; for (i = db + 1; i < bit[k]; i++) bb[i] = 0; static int x[256], y[256], z[256]; NTT_inline(k, aa, x); if (db == da) { for (i = 0; i <= da; i++) if (a[i] != b[i]) break; if (i <= da) NTT_inline(k, bb, y); else for (i = 0; i < bit[k]; i++) y[i] = x[i]; } else NTT_inline(k, bb, y); for (i = 0; i < bit[k]; i++) z[i] = (long long)x[i] * y[i] % Mod; NTT_reverse_inline(k, z, cc); for (i = 0; i <= da + db; i++) c[i] = (long long)cc[i] * bit_inv[k] % Mod; } // Compute the product of two polynomials a[0-da] and b[0-db] naively in O(da * db) time void prod_poly_naive(int da, int db, int a[], int b[], int c[]) { int i, j; static long long tmp[256]; for (i = 0; i <= da + db; i++) tmp[i] = 0; for (i = 0; i <= da; i++) for (j = 0; j <= db; j++) tmp[i+j] += (long long)a[i] * b[j] % Mod; for (i = 0; i <= da + db; i++) c[i] = tmp[i] % Mod; } // Compute the product of two polynomials a[0-da] and b[0-db] in an appropriate way void prod_polynomial(int da, int db, int a[], int b[], int c[]) { if (da <= 70 || db <= 70) prod_poly_naive(da, db, a, b, c); else prod_poly_NTT(da, db, a, b, c); } int main() { int i, N, M, K, A[200001]; scanf("%d %d %d", &N, &M, &K); for (i = 1; i <= N; i++) scanf("%d", &(A[i])); int j, k, l, ans[200001], tmp[256], res[256]; static int prod[200001][101]; for (l = 1; l + M - 1 <= N; l += M + 1) { for (k = 1, prod[l+M][0] = 1; k < K; k++) prod[l+M][k] = 0; for (i = l + M - 1; i >= l; i--) { for (k = 1, tmp[0] = 1; k < K; k++) tmp[k] = 0; tmp[A[i]]++; prod_polynomial(K - 1, K - 1, prod[i+1], tmp, res); for (k = 0; k < K; k++) { prod[i][k] = res[k] + res[k+K]; if (prod[i][k] >= Mod) prod[i][k] -= Mod; } } ans[l] = prod[l][0] - 1; for (k = 1, res[0] = 1; k < K; k++) res[k] = 0; for (i = l + 1; i <= l + M && i + M - 1 <= N; i++) { for (k = 1, tmp[0] = 1; k < K; k++) tmp[k] = 0; tmp[A[i+M-1]]++; prod_polynomial(K - 1, K - 1, res, tmp, res); for (k = 0; k < K; k++) { res[k] += res[k+K]; if (res[k] >= Mod) res[k] -= Mod; } prod_polynomial(K - 1, K - 1, prod[i], res, tmp); ans[i] = tmp[0] + tmp[K] - 1; if (ans[i] >= Mod) ans[i] -= Mod; } } for (i = 1; i <= N - M + 1; i++) printf("%d\n", ans[i]); fflush(stdout); return 0; }