Submission

Status:

x-x----x--

Subtask/Task Score:

0/100

Score: 0

User: konthaina_TH

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-05 11:46:04

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s,t;
    cin >> s >> t;
    int text1 = s.length();
    int text2 = t.length();

    vector<vector<int>> dp (text1+1,vector<int>(text2,0));
    for (int i=1;i<=text1;i++) {
        for (int j=1;j<=text2;j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i = text1;
    int j = text2;
    string ans = "";
    while( i >= 0 and j >= 0) {
        if (s[i] == s[j]) {
            ans += s[i];
            i--;
            j--;
        }
        else if (dp[i][j-1] > dp[i-1][j]) {
            j--;
        }
        else i--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << "\n";
    int temp = dp[text1][text2];
    cout << temp << "\n";
    if (temp > (s.length()/2)) cout << 'y';
    else cout << 'n';

}