Problem: 2050E - Three Strings
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
import java.util.*;

public class Solution {
    static int dp1[][];
    static int dp2[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while(t-->0){
            String a=sc.next();
            String b=sc.next();
            String c=sc.next();
           dp1=new int[a.length()+1][c.length()+1];
            dp2=new int[b.length()+1][c.length()+1];

            for(int i=0;i<=a.length();i++){
                Arrays.fill(dp1[i],Integer.MAX_VALUE);
            }
            for(int i=0;i<=b.length();i++){
                Arrays.fill(dp2[i],Integer.MAX_VALUE);
            }
            System.out.println(solve(a,b,c,0,0,0));

        }
    }
    public static int solve(String a,String b,String c,int i,int j,int k){
        if(i==a.length() || j==b.length()){
            return calc(a,b,c,i,j,k);
        }
        if(dp1[i][k]!=Integer.MAX_VALUE && dp2[j][k]!=Integer.MAX_VALUE){
            return Math.min(dp1[i][k],dp2[j][k]);
        }
        if(c.charAt(k)==a.charAt(i) && c.charAt(k)==b.charAt(j)){
            return Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=solve(a,b,c,i,j+1,k+1));

        }
        else if(c.charAt(k)==a.charAt(i) ){
            return Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=1+solve(a,b,c,i,j+1,k+1));
        }
        else if(c.charAt(k)==b.charAt(j)){
            return Math.min(dp2[j][k]=solve(a,b,c,i,j+1,k+1),dp1[i][k]=1+solve(a,b,c,i+1,j,k+1));
        }
        else return 1+Math.min(dp1[i][k]=solve(a,b,c,i+1,j,k+1),dp2[j][k]=solve(a,b,c,i,j+1,k+1));
    }

    public static int calc(String a,String b,String c,int i,int j,int k){
        int count=0;
        if(i==a.length()){
            while(j<b.length()){
                if(b.charAt(j)!=c.charAt(k)){
                   count++;
                }
                k++;
                j++;
            }

        }
        else{
            while(i<a.length()){
                if(a.charAt(i)!=c.charAt(k)){
                    count++;
                }
                i++;
                k++;
            }
        }
        return count;
    }
}

Submission (verdict: Accepted):
import java.util.*;

public class Solution {
    static int dp[][];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while(t-->0){
            String a=sc.next();
            String b=sc.next();
            String c=sc.next();
            dp=new int[a.length()+1][b.length()+1];

            for(int i=0;i<dp.length;i++){
                Arrays.fill(dp[i],-1);
            }
            System.out.println(solve(a,b,c,0,0,0));

        }
    }
    public static int solve(String a,String b,String c,int i,int j,int k){
        if(i==a.length() || j==b.length()){
            return calc(a,b,c,i,j,k);
        }
        if(dp[i][j]!=-1) return dp[i][j];
        if(c.charAt(k)==a.charAt(i) && c.charAt(k)==b.charAt(j)){
            return dp[i][j]=Math.min(solve(a,b,c,i+1,j,k+1),solve(a,b,c,i,j+1,k+1));

        }
        else if(c.charAt(k)==a.charAt(i) ){
            return dp[i][j]=Math.min(solve(a,b,c,i+1,j,k+1),1+solve(a,b,c,i,j+1,k+1));
        }
        else if(c.charAt(k)==b.charAt(j)){
            return dp[i][j]=Math.min(solve(a,b,c,i,j+1,k+1),1+solve(a,b,c,i+1,j,k+1));
        }
        else return dp[i][j]=1+Math.min(solve(a,b,c,i+1,j,k+1),solve(a,b,c,i,j+1,k+1));
    }

    public static int calc(String a,String b,String c,int i,int j,int k){
        int count=0;
        if(i==a.length()){
            while(j<b.length()){
                if(b.charAt(j)!=c.charAt(k)){
                    count++;
                }
                k++;
                j++;
            }

        }
        else{
            while(i<a.length()){
                if(a.charAt(i)!=c.charAt(k)){
                    count++;
                }
                i++;
                k++;
            }
        }
        return count;
    }
}