# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
356833 | nicolaalexandra | Round words (IZhO13_rowords) | C++14 | 48 ms | 16952 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.
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;
char a[DIM],b[DIM],a2[DIM],b2[DIM];
int dp_left[DIM][DIM],dp_right[DIM][DIM];
int n,m,i,j,sol;
void solve (char a[], char b[]){
memset (dp_left,0,sizeof dp_left);
memset (dp_right,0,sizeof dp_right);
dp_left[0][0] = 1;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++){
dp_left[i][j] = max (dp_left[i-1][j],dp_left[i][j-1]);
if (a[i] == b[j])
dp_left[i][j] = max (dp_left[i][j],dp_left[i-1][j-1] + 1);
}
dp_right[n+1][m+1] = 1;
for (i=n;i;i--)
for (j=m;j;j--){
dp_right[i][j] = max (dp_right[i+1][j],dp_right[i][j+1]);
if (a[i] == b[j])
dp_right[i][j] = max (dp_right[i][j],dp_right[i+1][j+1] + 1);
}
for (i=1;i<=n+1;i++)
for (j=1;j<=m+1;j++)
sol = max (sol,dp_right[i][j] + dp_left[i-1][j-1]);
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>a+1>>b+1;
n = strlen (a+1), m = strlen (b+1);
for (i=1;i<=n;i++)
a2[n-i+1] = a[i];
for (i=1;i<=m;i++)
b2[m-i+1] = b[i];
solve (a,b);
solve (a,b2);
solve (a2,b);
solve (a2,b2);
cout<<sol;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |