Submission

Status:
----------

Score: 0

User: Dormon

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2025-03-13 15:23:08

#include <iostream>
#include <cstdint>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>
#include <array>
#include <iomanip> // cout << fixed << setprecision(n);

using namespace std;
const bool TEST_CASE = 0;

template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
    std::cout << name << " : " << value << '\n';
}

template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args){
    const char* comma = strchr(names, ',');
    std::cout.write(names, comma - names) << " : " << value << " | ";
    Debug(comma + 1, args...);
}
template<typename T> 
ostream& operator<<(ostream& out, vector<T> &a){
    for (auto &x : a) out << x << ' '; 
    return out;
};

#define DORMON
#ifdef DORMON
    #define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
#else
    #define debug(...) 
#endif

void solve(){
    string a, b;
    cin >> a >> b;
    int n = a.size();

    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));

    string ans = "";
    for (int i = 1;i <= n;i++){
        for (int j = 1;j <= n;j++){
            if (a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    
    int i = n, j = n;
    while (i > 0 && j > 0){
        if (a[i - 1] == b[j - 1]){
            ans += a[i];
            i--;
            j--;
        }
        else if (dp[i - 1][j] > dp[i][j - 1])
            i--;
        else
            j--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
    cout << dp[n][n] << '\n';
    if (dp[n][n] > n/2)
        cout << 'y';
    else    
        cout << 'n';
    cout << '\n';
}


int main()
{
    #ifndef DORMON
        ios_base::sync_with_stdio(false); 
    #endif
    cin.tie(0);
    int q = 1; 
    if (TEST_CASE) cin >> q;
    while (q--){
        solve();
    }
}