Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: meme_boi2

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-19 00:23:52

#include <bits/stdc++.h>
using namespace std;
int dp[601][601];
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    string a, b;
    cin >>a >> b;
    int m = a.size(), n = b.size();
    string txt = "";
    for(int i = 1; i <= m; 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 if(dp[i-1][j] > dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = dp[i][j-1];
            }
        }
    }
    int i = m, j = n;
    while(i > 0 && j > 0){
        if(a[i-1] == b[j-1]){
            txt =  a[i-1] + txt;
            i--; j--;
        }
        else if(dp[i-1][j] > dp[i][j-1]){
                i--;
        }else{
                j--;
        }
    }
    
    cout << txt << '\n' << dp[m][n] << '\n';
    if(dp[m][n] >= max(a.length(),b.length())/2){
        cout << 'y';
    }else{
        cout << 'n';
    }
}
/*
c2_su65_dvaravati

cd "c:\Users\RICOH-NB110\Desktop\Computer Programing\gchan\" ; if ($?) { g++ c2_su65_dvaravati.cpp -o c2_su65_dvaravati } ; if ($?) { .\c2_su65_dvaravati}
*/