Submission

Status:

P---------

Subtask/Task Score:

10/100

Score: 10

User: C12

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-11 01:14:41

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;

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

    string s1,s2;

    cin >> s1;
    cin >> s2;

    int n1 = s1.length();
    int n2 = s2.length();

    int dp[601][601] = {0};

    
    for(int i = 1;i <= n1;i++){
        for(int j = 1;j <= n2;j++){
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            if(s1[i-1] == s2[j-1] && dp[i-1][j-1] + 1 > dp[i][j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
        }
    }

    // for(int i = 0;i <= n1;i++){
    //     for(int j = 0;j <= n2;j++){
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << '\n';
    // }
    
    int i = n1;
    int j = n2;

    string out;

    while(i > 0 && j > 0){
        if(i > 0 && dp[i][j] == dp[i-1][j]){
            i--;
        }
        if(j > 0 && dp[i][j] == dp[i][j-1]){
            j--;
        }
        // i--;
        // j--;
        
        i--;
        j--;
        if(s1[i] == s2[j]){
            out.push_back(s1[i]);
        }
    }
    reverse(out.begin(),out.end());
    cout << out << '\n';
    cout << dp[n1][n2] << '\n';
    if(dp[n1][n2] > n1/2){
        cout << 'y';
    }
    else{
        cout << 'n';
    }

}