Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: colo39

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.005 second

Submitted On: 2026-11-28 14:42:10

#include <bits/stdc++.h>
using namespace std;
int dp[1000][1000];

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string a,b;
    cin >> a >> b;
    
    a = "A"+a;
    b = "B"+b;
    for (int i = 1;i < a.size();i++) {
        for (int j = 1;j < b.size();j++) {
            if (a[i] == b[j]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    int x = a.size() - 1, y = b.size() - 1;
    string ans;
    while (x > 0 && y > 0) {
        if (a[x] == b[y]) {
            ans += a[x];
            x--;
            y--;
        } else {
            if (dp[x-1][y] > dp[x][y-1]) {
                x--;
            } else y--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << "\n" << ans.size() << "\n";
    if (ans.size() > (a.size() - 1) / 2) {
        cout << "y";
    } else cout << "n";
    return 0;
}