Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Kittiponn

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-05 09:55:10

/* #include <bits/stdc++.h>
#define ll long long
#define sp << ' ' <<
#define nl << '\n'
#define cnl cout << '\n'
using namespace std;
const int nx = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;
int dp[605][605];


int main(){
    cin.tie(0)->sync_with_stdio(0);
    string a,b;
    cin >> a >> b;
    int sz = a.size();
    for(int i = 1;i <= a.size();i++){
        for(int j = 1;j <= b.size();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]);
            cout << dp[i][j] << ' ';
        }
        cnl;
    }
    cout << dp[sz][sz] nl;
    int i = a.size(),j = b.size();
    string c;
    while(i > 0 && j > 0){cout << i sp j nl;
        if(a[i-1] == b[j-1])c += a[i-1],i--,j--;
        else if(dp[i-1][j] <= dp[i][j-1])j--;
        else i--;
    }
    reverse(c.begin(),c.end());
    cout << c;
}
// 8 5  */

#include <bits/stdc++.h>
#define ll long long
#define sp << ' ' <<
#define nl << '\n'
using namespace std;

int dp[605][605];

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    string a, b;
    if (!(cin >> b >> a))
        return 0;

    int sz = a.size();

    for (int i = 1; i <= sz; i++)
    {
        for (int j = 1; j <= sz; j++)
        {
            if (a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
                dp[i][j] = max(dp[i - 1][j],dp[i][j]);
        }
    }

    string c = "";
    int i = sz, j = sz;
    while (i > 0 && j > 0) {
        if (a[i - 1] == b[j - 1]) {
            c += a[i - 1];
            i--; j--;
        } 
        else if (dp[i-1][j] >= dp[i][j-1]) {
            i--; 
        } else {
            j--;
        }
        if(dp[i][j] == 0)break;
    }
    reverse(c.begin(), c.end());

    cout << c nl;
    cout << dp[sz][sz] nl;

    if (dp[sz][sz] > (sz / 2.0))
    {
        cout << "y" nl;
    }
    else
    {
        cout << "n" nl;
    }

    return 0;
}