Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x, y)                                                            \
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x, y, z)                                                         \
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z       \
       << " = " << (z) << endl;
#define showv(v)                                                               \
  rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  rep(i, n) cin >> a[i];
  vector<string> b(m);
  rep(i, m) cin >> b[i];

  // n = 5, m = 2

  // 0 1 2 3 4
  // 1 2 3 4 5
  // 2 3 4 5 6
  // 3 4 5 6 7
  // 4 5 6 7 8

  // 0 1
  // 1 2

  for (int i = 0; i + m <= n; ++i) {
    for (int j = 0; j + m <= n; ++j) {
      bool ok = true;
      for (int k = i; k < i + m; ++k) {
        if (a[k].substr(j, m) != b[k]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x, y)                                                            \
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x, y, z)                                                         \
  cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z       \
       << " = " << (z) << endl;
#define showv(v)                                                               \
  rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ');
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define uni(x) x.erase(unique(rng(x)), x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
// cout << fixed << setprecision(10);

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  rep(i, n) cin >> a[i];
  vector<string> b(m);
  rep(i, m) cin >> b[i];

  // n = 5, m = 2

  // 0 1 2 3 4
  // 1 2 3 4 5
  // 2 3 4 5 6
  // 3 4 5 6 7
  // 4 5 6 7 8

  // 0 1
  // 1 2

  for (int i = 0; i + m <= n; ++i) {
    for (int j = 0; j + m <= n; ++j) {
      bool ok = true;
      for (int k = i; k < i + m; ++k) {
        if (a[k].substr(j, m) != b[k - i]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}