Submission

Status:
PPPPPPPPPP

Score: 100

User: MiyaZaki1072

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.005 second

Submitted On: 2025-04-18 15:58:04

#include <bits/stdc++.h>
using namespace std;
int pth[660][660],dp[660][660];
const int di[] = {-1,0,-1};
const int dj[] = {0,-1,-1};
int main(){
    cin.tie(0)->sync_with_stdio(0);
    memset(pth,-1,sizeof pth);
    string a,b;cin>>a>>b;
    int n = a.size();
    int m = b.size();
    a = " " + a;
    b = " " + b;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i] == b[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
                pth[i][j] = 2;
            }
            else{
                if(dp[i][j-1] >= dp[i-1][j]){
                    dp[i][j] = dp[i][j-1];
                    pth[i][j] = 1;
                }
                else{
                    dp[i][j] = dp[i-1][j];
                    pth[i][j] = 0;
                }
            }
        }
    }
    stack<char>ans;
    int i=n,j=m;
    while(pth[i][j]!=-1){
        if(pth[i][j]==2)ans.push(a[i]);
        int pp = pth[i][j];
        i+=di[pp];
        j+=dj[pp];
    }
    while(ans.size())cout<<ans.top(),ans.pop();
    cout<<'\n'<<dp[n][m]<<'\n';
    if(dp[n][m]> n/2)cout<<"y\n";
    else cout<<"n\n";
}