#include <bits/stdc++.h> using namespace std; // https://judge.yosupo.jp/submission/46718 namespace ArbitraryModConvolution { template <typename T> struct Cp { T x, y; constexpr Cp() : x(0), y(0) {} constexpr Cp(T _x, T _y) : x(_x), y(_y) {} constexpr inline Cp operator+(const Cp& c) const { return Cp(x + c.x, y + c.y); } constexpr inline Cp operator-(const Cp& c) const { return Cp(x - c.x, y - c.y); } constexpr inline Cp operator*(const Cp& c) const { return Cp(x * c.x - y * c.y, x * c.y + y * c.x); } constexpr inline Cp operator-() const { return Cp(-x, -y); } constexpr inline Cp conj() const { return Cp(x, -y); } constexpr inline Cp rotl() const { return Cp(-y, x); } friend ostream& operator<<(ostream& os, const Cp& c) { os << "(" << c.x << ", " << c.y << ")" << endl; return os; } }; using C = Cp<double>; const long double PI = acosl(-1); struct CooleyTukey { static vector<C> w; static void setw(int k) { --k; if ((int)w.size() >= (1 << k)) return; w.resize(1 << k); vector<Cp<long double>> base(k); const long double arg = PI / (1 << k); for (int i = 0, j = 1 << (k - 1); j; i++, j >>= 1) { complex<long double> z = exp(complex<long double>(1i) * (arg * j)); base[i] = Cp<long double>{z.real(), z.imag()}; } genw(0, k - 1, Cp<long double>{1, 0}, base); } static void genw(int i, int b, Cp<long double> z, const vector<Cp<long double>>& base) { if (b == -1) { w[i].x = z.x, w[i].y = z.y; } else { genw(i, b - 1, z, base); genw(i | (1 << b), b - 1, z * base[b], base); } } static void fft(vector<C>& a, int k) { if (k <= 0) return; if (k == 1) { C a1 = a[1]; a[1] = a[0] - a[1]; a[0] = a[0] + a1; return; } if (k & 1) { int v = 1 << (k - 1); for (int j = 0; j < v; ++j) { C ajv = a[j + v]; a[j + v] = a[j] - ajv; a[j] = a[j] + ajv; } } int u = 1 << (k & 1), v = 1 << (k - 2 - (k & 1)); while (v) { { int j0 = 0; int j1 = v; int j2 = j1 + v; int j3 = j2 + v; int je = v; for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p2 = t0 + t2, t1p3 = t1 + t3; C t0m2 = t0 - t2, t1m3 = (t1 - t3) * w[1]; a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3; a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3; } } // jh >= 1 for (int jh = 1; jh < u; ++jh) { int j0 = jh * v * 4; int j1 = j0 + v; int j2 = j1 + v; int j3 = j2 + v; int je = j1; C ww = w[jh]; C xx = w[jh << 1]; C wx = ww * xx; for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1] * xx, t2 = a[j2] * ww, t3 = a[j3] * wx; C t0p2 = t0 + t2, t1p3 = t1 + t3; C t0m2 = t0 - t2, t1m3 = (t1 - t3) * w[1]; a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3; a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3; } } u <<= 2, v >>= 2; } } static void ifft(vector<C>& a, int k) { if ((int)a.size() <= 1) return; if (k == 1) { C a1 = a[1]; a[1] = a[0] - a[1]; a[0] = a[0] + a1; return; } int u = 1 << (k - 2); int v = 1; while (u) { // jh = 0 { int j0 = 0; int j1 = v; int j2 = j1 + v; int j3 = j2 + v; for (; j0 < v; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p1 = t0 + t1, t2p3 = t2 + t3; C t0m1 = t0 - t1, t2m3 = (t2 - t3) * w[1].conj(); a[j0] = t0p1 + t2p3, a[j2] = t0p1 - t2p3; a[j1] = t0m1 + t2m3, a[j3] = t0m1 - t2m3; } } // jh >= 1 for (int jh = 1; jh < u; ++jh) { int j0 = (jh * v) << 2; int j1 = j0 + v; int j2 = j1 + v; int j3 = j2 + v; int je = j1; C ww = w[jh].conj(); C xx = w[jh << 1].conj(); C yy = w[(jh << 1) + 1].conj(); for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p1 = t0 + t1, t2p3 = t2 + t3; C t0m1 = (t0 - t1) * xx, t2m3 = (t2 - t3) * yy; a[j0] = t0p1 + t2p3, a[j2] = (t0p1 - t2p3) * ww; a[j1] = t0m1 + t2m3, a[j3] = (t0m1 - t2m3) * ww; } } u >>= 2; v <<= 2; } if (k & 1) { u = 1 << (k - 1); for (int j = 0; j < u; j++) { C ajv = a[j] - a[j + u]; a[j] = a[j] + a[j + u]; a[j + u] = ajv; } } } static void fft_real(vector<C>& AL, vector<C>& AH, int k) { fft(AL, k); AH[0] = C{AL[0].y * 2.0, 0}; AL[0] = C{AL[0].x * 2.0, 0}; AH[1] = C{AL[1].y * 2.0, 0}; AL[1] = C{AL[1].x * 2.0, 0}; for (int i = 2, y = 2; y < (1 << k); y <<= 1) { for (; i < 2 * y; i += 2) { int j = i ^ (y - 1); AH[i] = (AL[j].conj() - AL[i]).rotl(); AL[i] = (AL[j].conj() + AL[i]); AH[j] = AH[i].conj(); AL[j] = AL[i].conj(); } } } // naive convolution template <typename T> static vector<long long> multiply(const vector<T>& s, const vector<T>& t) { int l = s.size() + t.size() - 1; int k = 2, M = 4; while (M < l) M <<= 1, ++k; setw(k); vector<C> a(M); for (int i = 0; i < (int)s.size(); i++) a[i].x = s[i]; for (int i = 0; i < (int)t.size(); i++) a[i].y = t[i]; fft(a, k); a[0].y = 4.0 * a[0].x * a[0].y; a[1].y = 4.0 * a[1].x * a[1].y; a[0].x = a[1].x = 0.0; for (int i = 2; i < M; i += 2) { int c = 1 << (31 - __builtin_clz(i)); int j = i ^ (c - 1); a[i] = (a[i] + a[j].conj()) * (a[i] - a[j].conj()); a[j] = -a[i].conj(); } vector<C> b(M / 2); for (int j = 0; j < M / 2; j++) { C tmp1 = a[j * 2 + 0] + a[j * 2 + 1]; C tmp2 = (a[j * 2 + 0] - a[j * 2 + 1]) * w[j].conj(); b[j] = tmp1 + tmp2.rotl(); } ifft(b, k - 1); vector<long long> u(l); for (int i = 0; i < l; i++) { if (i & 1) { u[i] = llround(-b[i >> 1].x / (4.0 * M)); } else { u[i] = llround(b[i >> 1].y / (4.0 * M)); } } return u; } template <unsigned int MOD> static vector<int> karatsuba(const vector<int>& a, const vector<int>& b) { using u64 = unsigned long long; constexpr u64 B = 32000; int l = a.size() + b.size() - 1; int k = 2, M = 4; while (M < l) M <<= 1, ++k; setw(k); vector<C> AL(M), AH(M), BL(M), BH(M); for (int i = 0; i < (int)a.size(); i++) { AL[i] = C{double(a[i] % B), double(a[i] / B)}; } for (int i = 0; i < (int)b.size(); i++) { BL[i] = C{double(b[i] % B), double(b[i] / B)}; } fft_real(AL, AH, k); fft_real(BL, BH, k); for (int i = 0; i < M; i++) { C tmp = AL[i] * BL[i] + (AH[i] * BH[i]).rotl(); BH[i] = AL[i] * BH[i] + (AH[i] * BL[i]).rotl(); BL[i] = tmp; } ifft(BL, k); ifft(BH, k); vector<int> u(l); double im = 1.0 / (4.0 * M); for (int i = 0; i < l; i++) { BL[i].x *= im, BL[i].y *= im; BH[i].x *= im, BH[i].y *= im; int x1 = u64(llround(BL[i].x)) % MOD; int x2 = u64(llround(BH[i].x) + llround(BH[i].y)) % MOD * B % MOD; int x3 = u64(llround(BL[i].y)) % MOD * (B * B % MOD) % MOD; if ((x1 += x2) >= (int)MOD) x1 -= MOD; if ((x1 += x3) >= (int)MOD) x1 -= MOD; u[i] = x1; } return u; } }; vector<C> CooleyTukey::w; // naive Toom-3 template <unsigned int MOD> vector<int> toom_3(const vector<int>& a, const vector<int>& b) { auto precalc = [](const vector<int>& _a) -> array<vector<int>, 5> { int n = _a.size(); vector<int> p0(n), p1(n), pm1(n), pm2(n), pinf(n); for (int i = 0; i < n; i++) { int m0 = _a[i] & 1023; int m1 = (_a[i] >> 10) & 1023; int m2 = (_a[i] >> 20) & 1023; p0[i] = m0; p1[i] = m0 + m1 + m2; pm1[i] = m0 - m1 + m2; pm2[i] = m0 - 2 * m1 + 4 * m2; pinf[i] = m2; } return {{p0, p1, pm1, pm2, pinf}}; }; auto [a0, a1, am1, am2, ainf] = precalc(a); auto [b0, b1, bm1, bm2, binf] = precalc(b); auto c0 = CooleyTukey::multiply(a0, b0); auto c1 = CooleyTukey::multiply(a1, b1); auto cm1 = CooleyTukey::multiply(am1, bm1); auto cm2 = CooleyTukey::multiply(am2, bm2); auto cinf = CooleyTukey::multiply(ainf, binf); vector<int> c(c0.size()); for (int i = 0; i < (int)c.size(); i++) { long long r0 = c0[i]; long long r4 = cinf[i]; long long r3 = (cm2[i] - c1[i]) / 3; long long r1 = (c1[i] - cm1[i]) / 2; long long r2 = cm1[i] - c0[i]; r3 = (r2 - r3) / 2 + r4 * 2; r2 += r1 - r4; r1 -= r3; long long ret = r4 % MOD * 1048576; ret += r3 % MOD * 1024 + r2; ret = ret % MOD * 1048576; ret += r1 % MOD * 1024 + r0; ret %= MOD; if (ret < 0) ret += MOD; c[i] = ret; } return c; } } // namespace ArbitraryModConvolution using namespace ArbitraryModConvolution; void mult(vector<int> &P, const vector<int> &Q) { P = CooleyTukey::karatsuba<1000000007>(P, Q); } /* void mult(vector<int> &P, const vector<int> &Q) { vector<int> W(P.size() + Q.size() - 1); for (int i = 0; i < (int) P.size(); i++) for (int j = 0; j < (int) Q.size(); j++) W[i + j] += P[i] * Q[j]; P = W; } */ const int N = 32; const int M = 24; int n, m, k; int get_value(int mask) { int value = 0; int now = 1 << (m - 1), half = 0; for (int j = 0; j < m; j++) { int bit = ((mask >> j) & 1); if (j > 0) { int old = ((mask >> (j - 1)) & 1); if (bit != old) half = true; } if (half) now >>= 1; assert(now > 0); if (bit) value += now; else value -= now; } return value; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> m >> k; int sum = 0; for (int i = 0; i < k; i++) { string s; cin >> s; int mask = 0; for (int j = 0; j < m; j++) if (s[j] == 'C') mask |= 1 << j; sum += get_value(mask); } if (sum == 0) cout << "1 "; else cout << "0 "; if (k < n) { vector<int> P(2 * (m * (1 << (m - 1))) + 1); const int half = m * (1 << (m - 1)); for (int i = 0; i < (1 << m); i++) { P[get_value(i) + half]++; } vector<int> Q = P; for (int i = k + 1; i <= n; i++) { cout << Q[-sum + (i - k) * half] << ' '; mult(Q, P); } } cout << '\n'; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | #include <bits/stdc++.h> using namespace std; // https://judge.yosupo.jp/submission/46718 namespace ArbitraryModConvolution { template <typename T> struct Cp { T x, y; constexpr Cp() : x(0), y(0) {} constexpr Cp(T _x, T _y) : x(_x), y(_y) {} constexpr inline Cp operator+(const Cp& c) const { return Cp(x + c.x, y + c.y); } constexpr inline Cp operator-(const Cp& c) const { return Cp(x - c.x, y - c.y); } constexpr inline Cp operator*(const Cp& c) const { return Cp(x * c.x - y * c.y, x * c.y + y * c.x); } constexpr inline Cp operator-() const { return Cp(-x, -y); } constexpr inline Cp conj() const { return Cp(x, -y); } constexpr inline Cp rotl() const { return Cp(-y, x); } friend ostream& operator<<(ostream& os, const Cp& c) { os << "(" << c.x << ", " << c.y << ")" << endl; return os; } }; using C = Cp<double>; const long double PI = acosl(-1); struct CooleyTukey { static vector<C> w; static void setw(int k) { --k; if ((int)w.size() >= (1 << k)) return; w.resize(1 << k); vector<Cp<long double>> base(k); const long double arg = PI / (1 << k); for (int i = 0, j = 1 << (k - 1); j; i++, j >>= 1) { complex<long double> z = exp(complex<long double>(1i) * (arg * j)); base[i] = Cp<long double>{z.real(), z.imag()}; } genw(0, k - 1, Cp<long double>{1, 0}, base); } static void genw(int i, int b, Cp<long double> z, const vector<Cp<long double>>& base) { if (b == -1) { w[i].x = z.x, w[i].y = z.y; } else { genw(i, b - 1, z, base); genw(i | (1 << b), b - 1, z * base[b], base); } } static void fft(vector<C>& a, int k) { if (k <= 0) return; if (k == 1) { C a1 = a[1]; a[1] = a[0] - a[1]; a[0] = a[0] + a1; return; } if (k & 1) { int v = 1 << (k - 1); for (int j = 0; j < v; ++j) { C ajv = a[j + v]; a[j + v] = a[j] - ajv; a[j] = a[j] + ajv; } } int u = 1 << (k & 1), v = 1 << (k - 2 - (k & 1)); while (v) { { int j0 = 0; int j1 = v; int j2 = j1 + v; int j3 = j2 + v; int je = v; for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p2 = t0 + t2, t1p3 = t1 + t3; C t0m2 = t0 - t2, t1m3 = (t1 - t3) * w[1]; a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3; a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3; } } // jh >= 1 for (int jh = 1; jh < u; ++jh) { int j0 = jh * v * 4; int j1 = j0 + v; int j2 = j1 + v; int j3 = j2 + v; int je = j1; C ww = w[jh]; C xx = w[jh << 1]; C wx = ww * xx; for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1] * xx, t2 = a[j2] * ww, t3 = a[j3] * wx; C t0p2 = t0 + t2, t1p3 = t1 + t3; C t0m2 = t0 - t2, t1m3 = (t1 - t3) * w[1]; a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3; a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3; } } u <<= 2, v >>= 2; } } static void ifft(vector<C>& a, int k) { if ((int)a.size() <= 1) return; if (k == 1) { C a1 = a[1]; a[1] = a[0] - a[1]; a[0] = a[0] + a1; return; } int u = 1 << (k - 2); int v = 1; while (u) { // jh = 0 { int j0 = 0; int j1 = v; int j2 = j1 + v; int j3 = j2 + v; for (; j0 < v; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p1 = t0 + t1, t2p3 = t2 + t3; C t0m1 = t0 - t1, t2m3 = (t2 - t3) * w[1].conj(); a[j0] = t0p1 + t2p3, a[j2] = t0p1 - t2p3; a[j1] = t0m1 + t2m3, a[j3] = t0m1 - t2m3; } } // jh >= 1 for (int jh = 1; jh < u; ++jh) { int j0 = (jh * v) << 2; int j1 = j0 + v; int j2 = j1 + v; int j3 = j2 + v; int je = j1; C ww = w[jh].conj(); C xx = w[jh << 1].conj(); C yy = w[(jh << 1) + 1].conj(); for (; j0 < je; ++j0, ++j1, ++j2, ++j3) { C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3]; C t0p1 = t0 + t1, t2p3 = t2 + t3; C t0m1 = (t0 - t1) * xx, t2m3 = (t2 - t3) * yy; a[j0] = t0p1 + t2p3, a[j2] = (t0p1 - t2p3) * ww; a[j1] = t0m1 + t2m3, a[j3] = (t0m1 - t2m3) * ww; } } u >>= 2; v <<= 2; } if (k & 1) { u = 1 << (k - 1); for (int j = 0; j < u; j++) { C ajv = a[j] - a[j + u]; a[j] = a[j] + a[j + u]; a[j + u] = ajv; } } } static void fft_real(vector<C>& AL, vector<C>& AH, int k) { fft(AL, k); AH[0] = C{AL[0].y * 2.0, 0}; AL[0] = C{AL[0].x * 2.0, 0}; AH[1] = C{AL[1].y * 2.0, 0}; AL[1] = C{AL[1].x * 2.0, 0}; for (int i = 2, y = 2; y < (1 << k); y <<= 1) { for (; i < 2 * y; i += 2) { int j = i ^ (y - 1); AH[i] = (AL[j].conj() - AL[i]).rotl(); AL[i] = (AL[j].conj() + AL[i]); AH[j] = AH[i].conj(); AL[j] = AL[i].conj(); } } } // naive convolution template <typename T> static vector<long long> multiply(const vector<T>& s, const vector<T>& t) { int l = s.size() + t.size() - 1; int k = 2, M = 4; while (M < l) M <<= 1, ++k; setw(k); vector<C> a(M); for (int i = 0; i < (int)s.size(); i++) a[i].x = s[i]; for (int i = 0; i < (int)t.size(); i++) a[i].y = t[i]; fft(a, k); a[0].y = 4.0 * a[0].x * a[0].y; a[1].y = 4.0 * a[1].x * a[1].y; a[0].x = a[1].x = 0.0; for (int i = 2; i < M; i += 2) { int c = 1 << (31 - __builtin_clz(i)); int j = i ^ (c - 1); a[i] = (a[i] + a[j].conj()) * (a[i] - a[j].conj()); a[j] = -a[i].conj(); } vector<C> b(M / 2); for (int j = 0; j < M / 2; j++) { C tmp1 = a[j * 2 + 0] + a[j * 2 + 1]; C tmp2 = (a[j * 2 + 0] - a[j * 2 + 1]) * w[j].conj(); b[j] = tmp1 + tmp2.rotl(); } ifft(b, k - 1); vector<long long> u(l); for (int i = 0; i < l; i++) { if (i & 1) { u[i] = llround(-b[i >> 1].x / (4.0 * M)); } else { u[i] = llround(b[i >> 1].y / (4.0 * M)); } } return u; } template <unsigned int MOD> static vector<int> karatsuba(const vector<int>& a, const vector<int>& b) { using u64 = unsigned long long; constexpr u64 B = 32000; int l = a.size() + b.size() - 1; int k = 2, M = 4; while (M < l) M <<= 1, ++k; setw(k); vector<C> AL(M), AH(M), BL(M), BH(M); for (int i = 0; i < (int)a.size(); i++) { AL[i] = C{double(a[i] % B), double(a[i] / B)}; } for (int i = 0; i < (int)b.size(); i++) { BL[i] = C{double(b[i] % B), double(b[i] / B)}; } fft_real(AL, AH, k); fft_real(BL, BH, k); for (int i = 0; i < M; i++) { C tmp = AL[i] * BL[i] + (AH[i] * BH[i]).rotl(); BH[i] = AL[i] * BH[i] + (AH[i] * BL[i]).rotl(); BL[i] = tmp; } ifft(BL, k); ifft(BH, k); vector<int> u(l); double im = 1.0 / (4.0 * M); for (int i = 0; i < l; i++) { BL[i].x *= im, BL[i].y *= im; BH[i].x *= im, BH[i].y *= im; int x1 = u64(llround(BL[i].x)) % MOD; int x2 = u64(llround(BH[i].x) + llround(BH[i].y)) % MOD * B % MOD; int x3 = u64(llround(BL[i].y)) % MOD * (B * B % MOD) % MOD; if ((x1 += x2) >= (int)MOD) x1 -= MOD; if ((x1 += x3) >= (int)MOD) x1 -= MOD; u[i] = x1; } return u; } }; vector<C> CooleyTukey::w; // naive Toom-3 template <unsigned int MOD> vector<int> toom_3(const vector<int>& a, const vector<int>& b) { auto precalc = [](const vector<int>& _a) -> array<vector<int>, 5> { int n = _a.size(); vector<int> p0(n), p1(n), pm1(n), pm2(n), pinf(n); for (int i = 0; i < n; i++) { int m0 = _a[i] & 1023; int m1 = (_a[i] >> 10) & 1023; int m2 = (_a[i] >> 20) & 1023; p0[i] = m0; p1[i] = m0 + m1 + m2; pm1[i] = m0 - m1 + m2; pm2[i] = m0 - 2 * m1 + 4 * m2; pinf[i] = m2; } return {{p0, p1, pm1, pm2, pinf}}; }; auto [a0, a1, am1, am2, ainf] = precalc(a); auto [b0, b1, bm1, bm2, binf] = precalc(b); auto c0 = CooleyTukey::multiply(a0, b0); auto c1 = CooleyTukey::multiply(a1, b1); auto cm1 = CooleyTukey::multiply(am1, bm1); auto cm2 = CooleyTukey::multiply(am2, bm2); auto cinf = CooleyTukey::multiply(ainf, binf); vector<int> c(c0.size()); for (int i = 0; i < (int)c.size(); i++) { long long r0 = c0[i]; long long r4 = cinf[i]; long long r3 = (cm2[i] - c1[i]) / 3; long long r1 = (c1[i] - cm1[i]) / 2; long long r2 = cm1[i] - c0[i]; r3 = (r2 - r3) / 2 + r4 * 2; r2 += r1 - r4; r1 -= r3; long long ret = r4 % MOD * 1048576; ret += r3 % MOD * 1024 + r2; ret = ret % MOD * 1048576; ret += r1 % MOD * 1024 + r0; ret %= MOD; if (ret < 0) ret += MOD; c[i] = ret; } return c; } } // namespace ArbitraryModConvolution using namespace ArbitraryModConvolution; void mult(vector<int> &P, const vector<int> &Q) { P = CooleyTukey::karatsuba<1000000007>(P, Q); } /* void mult(vector<int> &P, const vector<int> &Q) { vector<int> W(P.size() + Q.size() - 1); for (int i = 0; i < (int) P.size(); i++) for (int j = 0; j < (int) Q.size(); j++) W[i + j] += P[i] * Q[j]; P = W; } */ const int N = 32; const int M = 24; int n, m, k; int get_value(int mask) { int value = 0; int now = 1 << (m - 1), half = 0; for (int j = 0; j < m; j++) { int bit = ((mask >> j) & 1); if (j > 0) { int old = ((mask >> (j - 1)) & 1); if (bit != old) half = true; } if (half) now >>= 1; assert(now > 0); if (bit) value += now; else value -= now; } return value; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n >> m >> k; int sum = 0; for (int i = 0; i < k; i++) { string s; cin >> s; int mask = 0; for (int j = 0; j < m; j++) if (s[j] == 'C') mask |= 1 << j; sum += get_value(mask); } if (sum == 0) cout << "1 "; else cout << "0 "; if (k < n) { vector<int> P(2 * (m * (1 << (m - 1))) + 1); const int half = m * (1 << (m - 1)); for (int i = 0; i < (1 << m); i++) { P[get_value(i) + half]++; } vector<int> Q = P; for (int i = k + 1; i <= n; i++) { cout << Q[-sum + (i - k) * half] << ' '; mult(Q, P); } } cout << '\n'; return 0; } |