Submission
Status:
P--P---P--
Subtask/Task Score:
30/100
Score: 30
User: tHeNyXs
Problemset: Dvaravati-LCS
Language: cpp
Time: 0.004 second
Submitted On: 2026-03-06 09:52:25
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string a, b;
cin >> a >> b;
int n = a.length();
int m = b.length();
vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i-1] == b[j-1])
dp[i][j] = dp[i-1][j-1] + 1;
else
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
string ans = "";
int i = n, j = m;
while (i >= 1 && j >= 1) {
if (a[i-1] == b[j-1]) {
ans += a[i-1];
i--;
j--;
}
else if (dp[i-1][j] == dp[i][j])
i--;
else
j--;
}
reverse(ans.begin(), ans.end());
cout << ans << '\n';
cout << dp[n][m] << '\n';
cout << (dp[n][m] > n/2 ? "y" : "n");
return 0;
}