Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: konthaina_TH

Problemset: Dvaravati-LCS

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-05 13:41:44

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int text1 = s.length();
    int text2 = t.length();

    vector<vector<int>> dp (text1+1,vector<int>(text2+1,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-1] == t[j-1]) {
            ans += s[i-1];
            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.0)) cout << 'y';
    else cout << 'n';
    return 0;
}