# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97468 | Kastanda | Round words (IZhO13_rowords) | C++11 | 127 ms | 55032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 2009, NN = N * 2;
int n, m, dp[NN][N], P[NN][N];
char A[NN], B[N];
inline int RLCS()
{
int Mx = 0;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (A[i] == B[j])});
if (dp[i][j] == dp[i][j - 1])
P[i][j] = 2;
else if (A[i] == B[j] && dp[i][j] == dp[i - 1][j - 1] + 1)
P[i][j] = 1;
else
P[i][j] = 0;
}
Mx = dp[n][m];
for (int i = n + 1; i <= n + n; i++)
{
/* **** Deleting the first row **** */
int last = i - n;
for (int j = 1; j <= m; j++)
{
if (last != i && P[last][j] != 2)
{
P[last][j] = 2;
last ++;
while (last < i && P[last][j] == 0)
P[last][j] = 2, last ++;
}
if (last == i)
dp[i - 1][j] --;
}
/* **** Adding the last row **** */
for (int j = 1; j <= m; j++)
{
dp[i][j] = max({dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + (A[i] == B[j])});
if (dp[i][j] == dp[i][j - 1])
P[i][j] = 2;
else if (A[i] == B[j] && dp[i][j] == dp[i - 1][j - 1] + 1)
P[i][j] = 1;
else
P[i][j] = 0;
}
Mx = max(Mx, dp[i][m]);
}
return (Mx);
}
int main()
{
scanf("%s%s", A + 1, B + 1);
n = strlen(A + 1);
m = strlen(B + 1);
memcpy(A + n + 1, A + 1, n);
int Mx = RLCS();
reverse(B + 1, B + m + 1);
return !printf("%d\n", max(Mx, RLCS()));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |