Submission
Status:
P--P---P--
Subtask/Task Score:
30/100
Score: 30
User: KantaponZ
Problemset: Dvaravati-LCS
Language: cpp
Time: 0.004 second
Submitted On: 2025-11-08 23:18:40
#include <bits/stdc++.h>
using namespace std;
int dp[605][605];
int par[605][605];
string a, b;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> a >> b;
int N = a.size();
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
par[i][j] = 1;
} else {
if (dp[i - 1][j] >= dp[i][j - 1]) {
par[i][j] = 2;
} else {
par[i][j] = 3;
}
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
string best = "";
int i = N, j = N;
while (i > 0 && j > 0) {
if (par[i][j] == 1) {
best += a[i - 1];
i--;
j--;
} else {
if (par[i][j] == 2) {
i--;
} else if (par[i][j] == 3){
j--;
}
}
}
reverse(best.begin(), best.end());
cout << best << "\n" << dp[N][N] << "\n" << (dp[N][N] > N / 2 ? 'y' : 'n');
}