Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class FMT {
public:
    // P < 2^31
    static constexpr uint32_t N = 1 << 27, W = 137, P = 15 * N + 1;

    FMT() : nx_(n_), ny_(1) {
        data_.resize(n_);
    }
    FMT(int nx, int ny) : nx_(nx), ny_(ny) {
        if ((nx & -nx) != nx || nx < 1 || nx > n_) throw;
        if ((ny & -ny) != ny || ny < 1 || ny > n_) throw;
        data_.resize(nx * ny);
    }

    static void init(int n) {
        if ((n & -n) != n || n < 1 || n > N) throw;

        n_ = n;
        if (n_ < 4) return;

        // Wのべき乗のテーブル
        w_ = (uint32_t *)malloc(n_ * 2 * sizeof *w_);
        w_[0] = 1;
        w_[1] = W;
        for (int n = n_; n < N; n *= 2) {
            w_[1] = mul(w_[1], w_[1]);
        }
        for (int i = 2; i < n_ / 2; i++) {
            w_[i] = mul(w_[i - 1], w_[1]);
        }
        // 各階層ごとに用意
        uint32_t *w = w_, *w1 = w_ + n_ / 2;
        for (int j = n_ / 4; j != 0; j /= 2) {
            for (int i = 0; i < j; i++) {
                *w1 = *w;
                w += 2;
                w1 += 1;
            }
        }
        // 反対側
        const uint32_t r2 = mul(w_[n_ / 4], w_[n_ / 4]);
        w = w_;
        for (int j = n_ / 2; j != 0; j /= 2) {
            w[n_] = 1;
            for (int i = 1; i < j; i++) {
                w[j - i + n_] = mul(w[i], r2);
            }
            w += j;
        }
    }
    static void uninit() {
        free(w_);
    }

    static uint32_t add(uint32_t a1, uint32_t a2) {
        const uint32_t t = a1 + a2;
        return t < P ? t : t - P;
    }
    static uint32_t sub(uint32_t a1, uint32_t a2) {
        const uint32_t t = a1 - a2;
        return t < P ? t : t + P;
    }
    static uint32_t mul(uint32_t a1, uint32_t a2) {
        return (uint64_t)a1 * (uint64_t)a2 % (uint64_t)P;
    }
    static uint32_t inv(uint32_t n) { // nは2冪
        return n == 1 ? 1 : P - P / n;
    }

    uint32_t *data() {
        return &data_[0];
    }
    uint32_t *operator[](size_t y) {
        return &data_[nx_ * y];
    }
    void fmt(int sign) {
        auto f = [&](int n, int s, int m, int k) {
            for (int i = 0; i < k; i++) {
                if (n > 2) {
                    if (sign > 0) {
                        fmt_f(n, s, &data_[m * i], w_ + (n_ - n));
                    } else {
                        fmt_t(n, s, &data_[m * i], w_ + n_ + (n_ - n));
                    }
                } else if (n == 2) {
                    fmt_2(s, &data_[n * i]);
                }
            }
        };
        f(nx_, 1, nx_, ny_);
        f(ny_, nx_, 1, nx_);
    }

private:
    static int n_;
    static uint32_t *w_;
    std::vector<uint32_t> data_;
    int nx_, ny_;

    static void fmt_f(int n, int s, uint32_t *p, uint32_t *w) {
        const int m = n / 2;

        for (int i = 0; i < m; i++) {
            const int j = i + m;
            const uint32_t t0 = add(p[i * s], p[j * s]);
            const uint32_t t1 = mul(p[i * s] - p[j * s] + P, w[i]);
            p[i * s] = t0;
            p[j * s] = t1;
        }

        if (m == 2) {
            fmt_2(s, p);
            fmt_2(s, p + 2 * s);
        } else {
            fmt_f(m, s, p, w + m);
            fmt_f(m, s, p + m * s, w + m);
        }
    }
    static void fmt_t(int n, int s, uint32_t *p, uint32_t *w) {
        const int m = n / 2;

        if (m == 2) {
            fmt_2(s, p);
            fmt_2(s, p + 2 * s);
        } else {
            fmt_t(m, s, p, w + m);
            fmt_t(m, s, p + m * s, w + m);
        }

        for (int i = 0; i < m; i++) {
            int j = i + m;
            const uint32_t t0 = mul(w[i], p[j * s]);
            p[j * s] = sub(p[i * s], t0);
            p[i * s] = add(p[i * s], t0);
        }
    }
    static void fmt_2(int s, uint32_t *p) {
        const uint32_t t0 = add(p[0], p[s]);
        const uint32_t t1 = sub(p[0], p[s]);
        p[0] = t0;
        p[s] = t1;
    }
};

int FMT::n_;
uint32_t *FMT::w_;

int main() {
    int n, m, l;
    cin >> n >> m;
    for (l = 1; l < n; l *= 2);
    FMT::init(l);
    FMT a(l, l), b(l, l);
    string s;
    memset(a.data(), 0, l * l * 4);
    memset(b.data(), 0, l * l * 4);
    for (int y = 0; y < n; y++) {
        cin >> s;
        for (int x = 0; x < n; x++) {
            a[y][x] = s[x] == '#' ? FMT::P - 1 : 1;
        }
    }
    for (int y = 0; y < m; y++) {
        cin >> s;
        for (int x = 0; x < m; x++) {
            b[y == 0 ? 0 : l - y][x == 0 ? 0 : l - x] = s[x] == '#' ? FMT::P - 1 : 1;
        }
    }

    a.fmt(+1);
    b.fmt(+1);
    for (int i = 0; i < l * l; i++) {
        a[0][i] = FMT::mul(a[0][i], b[0][i]);
    }
    a.fmt(-1);

    int k = n - m + 1;
    for (int y = 0; y < k; y++) {
        for (int x = 0; x < k; x++) {
            //uint32_t t = FMT::mul(a[y][x], FMT::inv(l * l));
            //cout << x << " " << y << " " << (int32_t)(t < FMT::P / 2 ? t : t - FMT::P) << endl;
            if (a[y][x] == m * m * l * l) {
                cout << "Yes" << endl;
                quick_exit(0);
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Compiler output:
a.cc:10:22: error: 'uint32_t' does not name a type
   10 |     static constexpr uint32_t N = 1 << 27, W = 137, P = 15 * N + 1;
      |                      ^~~~~~~~
a.cc:5:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    4 | #include <algorithm>
  +++ |+#include <cstdint>
    5 | using namespace std;
a.cc:61:12: error: 'uint32_t' does not name a type
   61 |     static uint32_t add(uint32_t a1, uint32_t a2) {
      |            ^~~~~~~~
a.cc:61:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:65:12: error: 'uint32_t' does not name a type
   65 |     static uint32_t sub(uint32_t a1, uint32_t a2) {
      |            ^~~~~~~~
a.cc:65:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:69:12: error: 'uint32_t' does not name a type
   69 |     static uint32_t mul(uint32_t a1, uint32_t a2) {
      |            ^~~~~~~~
a.cc:69:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:72:12: error: 'uint32_t' does not name a type
   72 |     static uint32_t inv(uint32_t n) { // nは2冪
      |            ^~~~~~~~
a.cc:72:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:76:5: error: 'uint32_t' does not name a type
   76 |     uint32_t *data() {
      |     ^~~~~~~~
a.cc:76:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:79:5: error: 'uint32_t' does not name a type
   79 |     uint32_t *operator[](size_t y) {
      |     ^~~~~~~~
a.cc:79:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:102:12: error: 'uint32_t' does not name a type
  102 |     static uint32_t *w_;
      |            ^~~~~~~~
a.cc:102:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:103:17: error: 'uint32_t' was not declared in this scope
  103 |     std::vector<uint32_t> data_;
      |                 ^~~~~~~~
a.cc:103:17: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:103:25: error: template argument 1 is invalid
  103 |     std::vector<uint32_t> data_;
      |                         ^
a.cc:103:25: error: template argument 2 is invalid
a.cc:106:37: error: 'uint32_t' has not been declared
  106 |     static void fmt_f(int n, int s, uint32_t *p, uint32_t *w) {
      |                                     ^~~~~~~~
a.cc:106:50: error: 'uint32_t' has not been declared
  106 |     static void fmt_f(int n, int s, uint32_t *p, uint32_t *w) {
      |                                                  ^~~~~~~~
a.cc:125:37: error: 'uint32_t' has not been declared
  125 |     static void fmt_t(int n, int s, uint32_t *p, uint32_t *w) {
      |                                     ^~~~~~~~
a.cc:125:50: error: 'uint32_t' has not been declared
  125 |     static void fmt_t(int n, int s, uint32_t *p, uint32_t *w) {
      |                                                  ^~~~~~~~
a.cc:143:30: error: 'uint32_t' has not been declared
  143 |     static void fmt_2(int s, uint32_t *p) {
      |                              ^~~~~~~~
a.cc: In constructor 'FMT::FMT()':
a.cc:13:15: error: request for member 'resize' in '((FMT*)this)->FMT::data_', which is of non-class type 'int'
   13 |         data_.resize(n_);
      |               ^~~~~~
a.cc: In constructor 'FMT::FMT(int, int)':
a.cc:18:15: error: request for member 'resize' in '((FMT*)this)->FMT::data_', which is of non-class type 'int'
   18 |         data_.resize(nx * ny);
      |               ^~~~~~
a.cc: In static member function 'static void FMT::init(int)':
a.cc:22:43: error: 'N' was not declared in this scope
   22 |         if ((n & -n) != n || n < 1 || n > N) throw;
      |                                           ^
a.cc:28:9: error: 'w_' was not declared in this scope; did you mean 'n_'?
   28 |         w_ = (uint32_t *)malloc(n_ * 2 * sizeof *w_);
      |         ^~
      |         n_
a.cc:28:15: error: 'uint32_t' was not declared in this scope
   28 |         w_ = (uint32_t *)malloc(n_ * 2 * sizeof *w_);
      |               ^~~~~~~~
a.cc:28:15: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:28:25: error: expected primary-expression before ')' token
   28 |         w_ = (uint32_t *)malloc(n_ * 2 * sizeof *w_);
      |                         ^
a.cc:30:17: error: 'W' was not declared in this scope
   30 |         w_[1] = W;
      |                 ^
a.cc:31:30: error: 'N' was not declared in this scope
   31 |         for (int n = n_; n < N; n *= 2) {
      |                              ^
a.cc:32:21: error: 'mul' was not declared in this scope
   32 |             w_[1] = mul(w_[1], w_[1]);
      |                     ^~~
a.cc:35:21: error: 'mul' was not declared in this scope
   35 |             w_[i] = mul(w_[i - 1], w_[1]);
      |                     ^~~
a.cc:38:19: error: 'w' was not declared in this scope
   38 |         uint32_t *w = w_, *w1 = w_ + n_ / 2;
      |                   ^
a.cc:38:28: error: 'w1' was not declared in this scope
   38 |         uint32_t *w = w_, *w1 = w_ + n_ / 2;
      |                            ^~
a.cc:47:15: error: 'uint32_t' does not name a type
   47 |         const uint32_t r2 = mul(w_[n_ / 4], w_[n_ / 4]);
      |               ^~~~~~~~
a.cc:47:15: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:52:43: error: 'r2' was not declared in this scope
   52 |                 w[j - i + n_] = mul(w[i], r2);
      |                                           ^~
a.cc:52:33: error: 'mul' was not declared in this scope
   52 |                 w[j - i + n_] = mul(w[i], r2);
      |                                 ^~~
a.cc: In static member function 'static void FMT::uninit()':
a.cc:58:14: error: 'w_' was not declared in this scope; did you mean 'n_'?
   58 |         free(w_);
      |              ^~
      |              n_
a.cc: In lambda function:
a.cc:87:43: error: invalid types 'int[int]' for array subscript
   87 |                         fmt_f(n, s, &data_[m * i], w_ + (n_ - n));
      |                                           ^
a.cc:87:52: error: 'w_' was not declared in this scope; did you mean 'n_'?
   87 |                         fmt_f(n, s, &data_[m * i], w_ + (n_ - n));
      |                                                    ^~
      |                                                    n_
a.cc:89:43: error: invalid types 'int[int]' for array subscript
   89 |                         fmt_t(n, s, &data_[m * i], w_ + n_ + (n_ - n));
      |                                           ^
a.cc:89:52: error: 'w_' was not declared in this scope; did you mean 'n_'?
   89 |                         fmt_t(n, s, &data_[m * i], w_ + n_ + (n_ - n));
      |                                                    ^~
      |                                                    n_
a.cc:92:36: error: invalid types 'int[int]' for array subscript
   92 |                     fmt_2(s, &data_[n * i]);
      |                                    ^
a.cc: In static member function 'static void FMT::fmt_f(int, int, int*, int*)':
a.cc:111:19: error: 'uint32_t' does not name a type
  111 |             const uint32_t t0 = add(p[i * s], p[j * s]);
      |                   ^~~~~~~~
a.cc:111:19: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:112:19: error: 'uint32_t' does not name a type
  112 |             const uint32_t t1 = mul(p[i * s] - p[j * s] + P, w[i]);
      |                   ^~~~~~~~
a.cc:112:19: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:113:24: error: 't0' was not declared in this scope; did you mean 'tm'?
  113 |             p[i * s] = t0;
      |                        ^~
      |                        tm
a.cc:114:24: error: 't1' was not declared in this scope; did you mean 'tm'?
  114 |             p[j * s] = t1;
      |                        ^~
      |                        tm
a.cc: In static member function 'static void FMT::fmt_t(int, int, int*, int*)':
a.cc:138:19: error: 'uint32_t' does not name a type
  138 |             const uint32_t t0 = mul(w[i], p[j * s]);
      |                   ^~~~~~~~
a.cc:138:19: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:139:38: error: 't0' was not declared in this scope; did you mean 'tm'?
  139 |             p[j * s] = sub(p[i * s], t0);
      |                                      ^~
      |                                      tm
a.cc:139:24: error: 'sub' was not declared in this scope
  139 |             p[j * s] = sub(p[i * s], t0);
      |                        ^~~
a.cc:140:24: error: 'add' was not declared in this scope
  140 |             p[i * s] = add(p[i * s], t0);
      |                        ^~~
a.cc: In static member function 'static void FMT::fmt_2(int, int*)':
a.cc:144:15: error: 'uint32_t' does not name a type
  144 |         const uint32_t t0 = add(p[0], p[s]);
      |               ^~~~~~~~
a.cc:144:15: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:145:15: error: 'uint32_t' does not name a type
  145 |         const uint32_t t1 = sub(p[0], p[s]);
      |               ^~~~~~~~
a.cc:145:15: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:146:16: error: 't0' was not declared in this scope; did you mean 'tm'?
  146 |         p[0] = t0;
      |                ^~
      |                tm
a.cc:147:16: error: 't1' was not declared in this scope; did you mean 'tm'?
  147 |         p[s] = t1;
      |                ^~
      |                tm
a.cc: At global scope:
a.cc:152:1: error: 'uint32_t' does not name a type
  152 | uint32_t *FMT::w_;