Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;

int minChanges(string &a, string &b, string &c) {
    int n = a.length(), m = b.length();
    vector<int> prev(m + 1, 0), curr(m + 1, 0);

    // Initialize base cases
    for (int j = 0; j <= m; ++j) {
        prev[j] = j; // Only use characters from `b`
    }

    for (int i = 0; i <= n; ++i) {
        curr[0] = i; // Only use characters from `a`

        for (int j = 0; j <= m; ++j) {
            if (i == 0 && j == 0) continue; // Base case already handled
            int k = i + j - 1; // Current index in `c`

            curr[j] = INT_MAX; // Initialize to a large value

            if (i > 0 && a[i - 1] == c[k]) { // Match with `a`
                curr[j] = min(curr[j], prev[j]);
            } else if (i > 0) { // Mismatch with `a`
                curr[j] = min(curr[j], prev[j] + 1);
            }

            if (j > 0 && b[j - 1] == c[k]) { // Match with `b`
                curr[j] = min(curr[j], curr[j - 1]);
            } else if (j > 0) { // Mismatch with `b`
                curr[j] = min(curr[j], curr[j - 1] + 1);
            }
        }

        // Swap `prev` and `curr`
        swap(prev, curr);
    }

    return prev[m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        cout << minChanges(a, b, c) << '\n';
    }

    return 0;
}


Solution 2 (runtime: 93 ms):
//#include "dec24_1.h"

#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>

using namespace std;

int SolveHelper(std::vector<std::vector<int>>& dp, std::string_view string1,
                std::string_view string2, std::string_view string3, int p1,
                int p2, int p3) {
  if (dp[p1][p2] != -1) return dp[p1][p2];
  if (p1 == string1.size()) {
    if (dp[p1][p2] != -1) return dp[p1][p2];
    int count = 0;
    for (int i = p2; i < string2.size(); i++) {
      if (string2[i] != string3[p1 + i]) {
        count++;
      }
    }
    dp[p1][p2] = count;
    return count;
  }

  if (p2 == string2.size()) {
    int count = 0;
    for (int i = p1; i < string1.size(); i++) {
      if (string1[i] != string3[p2 + i]) {
        count++;
      }
    }
    dp[p1][p2] = count;
    return count;
  }
  int x;
  if (string1[p1] == string3[p3]) {
    x = SolveHelper(dp, string1, string2, string3, p1 + 1, p2, p3 + 1);
  } else {
    x = SolveHelper(dp, string1, string2, string3, p1 + 1, p2, p3 + 1) + 1;
  }
  if (string2[p2] == string3[p3]) {
    x = std::min(x,
          SolveHelper(dp, string1, string2, string3, p1, p2 + 1, p3 + 1));
  } else {
    x = std::min(x,
          SolveHelper(dp, string1, string2, string3, p1, p2 + 1, p3 + 1) + 1);
  }
  dp[p1][p2] = x;
  return x;
}

class Problem {
 public:
  Problem() = default;
  int Solve(std::vector<std::vector<int>>& dp,
            std::string_view string1,
            std::string_view string2,
            std::string_view string3) {
    return SolveHelper(dp, string1, string2, string3, 0, 0, 0);
  }
};

int main() {
  int n;
  cin >> n;
  std::vector<int> output;
  for (int i = 0; i < n; i++) {
    std::string string1, string2, string3;
    Problem problem;
    cin >> string1;
    cin >> string2;
    cin >> string3;
    std::vector<std::vector<int>> matrix(string1.size() + 1,
                                          std::vector<int>(string2.size() + 1,
                                                           -1));
    output.push_back(problem.Solve(matrix, std::string_view(string1),
                                   std::string_view(string2),
                                   std::string_view(string3)));
  }
  for (int i = 0; i < n; i++) {
    cout << output[i] << endl;
  }

  return 0;
}