Language: C++

#include <bits/stdc++.h>
#define ll long long
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll dp[4001][4001];

ll f(string s1,string s2,ll i,ll j,ll n,ll m){
  if(i==n || j==m){return 0;}
  if(dp[i][j]!=-1){return dp[i][j];} 
  ll ans;
  if(s1[i]==s2[j]){ ans = 1 + f(s1,s2,i+1,j+1,n,m);}
  else{
      ans = max(f(s1,s2,i+1,j,n,m),f(s1,s2,i,j+1,n,m));
  }
  dp[i][j] = ans;
  return ans;
}

void print_f(string s1,string s2,ll i,ll j,ll n,ll m,string &t){
    if(i==n || j==m){}
    else{
        if(s1[i]==s2[j]){
            t.pb(s1[i]);
            print_f(s1,s2,i+1,j+1,n,m,t);
        }
        else{
            if(f(dp[i+1][j]==dp[i][j]){
                print_f(s1,s2,i+1,j,n,m,t);
            }
            else{print_f(s1,s2,i,j+1,n,m,t);}
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll t; 
    // cin>>t;
    t=1;
    while(t--){
     memset(dp,-1,sizeof(dp));
     string s1,s2; cin>>s1>>s2;
     ll n,m;
     n = s1.length(); m = s2.length();
     ll q = f(s1,s2,0,0,n,m);
     string t;
     print_f(s1,s2,0,0,n,m,t);
     cout<<t;
    }
}


Compiler output:
a.cc: In function 'void print_f(std::string, std::string, long long int, long long int, long long int, long long int, std::string&)':
a.cc:73:28: error: could not convert '(dp[(i + 1)][j] == dp[i][j])' from 'bool' to 'std::string' {aka 'std::__cxx11::basic_string<char>'}
   73 |             if(f(dp[i+1][j]==dp[i][j]){
      |                  ~~~~~~~~~~^~~~~~~~~~
      |                            |
      |                            bool
a.cc:73:39: error: expected ')' before '{' token
   73 |             if(f(dp[i+1][j]==dp[i][j]){
      |               ~                       ^
      |                                       )
a.cc:77:9: error: expected primary-expression before '}' token
   77 |         }
      |         ^