Problem p02751 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include <any>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)

using namespace std;

typedef long long ll;
typedef double dbl;

template <typename T> void print(const vector<T> &s) {
  for (auto x : s)
    cout << x << "";
  cout << endl;
}

template <class T> void print(const T *s, int n) {
  for (int i = 0; i < n; i++)
    cout << s[i] << "";
  cout << endl;
}

template <class T> void print(vector<vector<T>> s) {
  for (int i = 0; i < s.size(); i++)
    print(s[i]);
}

auto build(int n, int m, int t) {
  if (n == 0 || m == 0)
    return vector<vector<int>>();
  auto kek = build(n - 1, m - 1, t ^ 1);
  // print(kek);
  int nn = (1 << (n - 1)) - 1, mm = (1 << (m - 1)) - 1;
  n = (1 << n) - 1, m = (1 << m) - 1;
  vector<vector<int>> s(n, vector<int>(m));
  if (t) {
    for (int i = 0; i < n; i++)
      s[i][m / 2] = 1;
    for (int i = 0; i < m; i++)
      s[n / 2][i] = 1;
  }
  s[n / 2][m / 2] = 1;
  for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
      for (int i = 0; i < nn; i++) {
        for (int j = 0; j < mm; j++) {
          s[x * (nn + 1) + i][y * (mm + 1) + j] = kek[i][j];
        }
      }
    }
  }
  return s;
}

int solve() {
  int n, m;
  cin >> n >> m;
  assert(n < 5 && m < 5);
  auto res = build(n, m, 0);
  print(res);
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include <any>

#define prev asasddlsa
#define rank aljds

#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i++)

using namespace std;

typedef long long ll;
typedef double dbl;

template <typename T> void print(const vector<T> &s) {
  for (auto x : s)
    cout << x << "";
  cout << endl;
}

template <class T> void print(const T *s, int n) {
  for (int i = 0; i < n; i++)
    cout << s[i] << "";
  cout << endl;
}

template <class T> void print(vector<vector<T>> s) {
  for (int i = 0; i < s.size(); i++)
    print(s[i]);
}

auto build(int n, int m, int t) {
  if (n == 0 || m == 0)
    return vector<vector<int>>();
  auto kek = build(n - 1, m - 1, t ^ 1);
  // print(kek);
  int nn = (1 << (n - 1)) - 1, mm = (1 << (m - 1)) - 1;
  n = (1 << n) - 1, m = (1 << m) - 1;
  vector<vector<int>> s(n, vector<int>(m));
  if (t) {
    for (int i = 0; i < n; i++)
      s[i][m / 2] = 1;
    for (int i = 0; i < m; i++)
      s[n / 2][i] = 1;
  }
  s[n / 2][m / 2] = 1;
  for (int x = 0; x < 2; x++) {
    for (int y = 0; y < 2; y++) {
      for (int i = 0; i < nn; i++) {
        for (int j = 0; j < mm; j++) {
          s[x * (nn + 1) + i][y * (mm + 1) + j] = kek[i][j];
        }
      }
    }
  }
  return s;
}

int solve() {
  int n, m;
  cin >> n >> m;
  auto res = build(n, m, min(n, m) & 1);
  print(res);
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}