Problem p03165 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define fastread                                                               \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a)                                                               \
  for (auto x : a)                                                             \
    cout << x << ' ';                                                          \
  cout << endl;
#define printM(b)                                                              \
  for (auto y : b) {                                                           \
    print(y);                                                                  \
  }
#define printP(p) cout << p.first << ' ' << p.second << endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
  fastread;

  ll n, m, i, j;
  string s, t;

  cin >> s >> t;

  n = s.length();
  m = t.length();

  string dp[2][m + 1];

  for (i = 0; i <= n; ++i)
    for (j = 0; j <= m; ++j) {
      if (i == 0 || j == 0)
        dp[i % 2][j] = "";
      else if (s[i - 1] == t[j - 1])
        dp[i % 2][j] = dp[(i + 1) % 2][j - 1] + s[i - 1];
      else {
        if (dp[(i + 1) % 2][j].length() >= dp[i % 2][j - 1].length())
          dp[i % 2][j] = dp[(i + 1) % 2][j];
        else
          dp[i % 2][j] = dp[i % 2][j - 1];
      }
    }

  cout << dp[n % 2][m];

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define fastread                                                               \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a)                                                               \
  for (auto x : a)                                                             \
    cout << x << ' ';                                                          \
  cout << endl;
#define printM(b)                                                              \
  for (auto y : b) {                                                           \
    print(y);                                                                  \
  }
#define printP(p) cout << p.first << ' ' << p.second << endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
  fastread;

  ll n, m, i, j;
  string s, t;

  cin >> s >> t;

  n = s.length();
  m = t.length();

  string dp[2][m + 1];

  for (j = 0; j <= m; ++j)
    dp[0][j] = "";
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (s[i - 1] == t[j - 1])
        dp[i % 2][j] = dp[(i + 1) % 2][j - 1] + s[i - 1];
      else {
        if (dp[(i + 1) % 2][j].length() >= dp[i % 2][j - 1].length())
          dp[i % 2][j] = dp[(i + 1) % 2][j];
        else
          dp[i % 2][j] = dp[i % 2][j - 1];
      }
    }

  cout << dp[n % 2][m];

  return 0;
}