# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
357660 | nicolaalexandra | Round words (IZhO13_rowords) | C++14 | 100 ms | 32876 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 2010
using namespace std;
char a[DIM],b[DIM],a2[DIM],b2[DIM];
int dp[DIM][DIM];
int n,m,i,j,sol;
void solve (char a[], char b[]){
memset (dp,0,sizeof dp);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++){
dp[i][j] = max (dp[i-1][j],dp[i][j-1]);
if (a[i] == b[j])
dp[i][j] = max (dp[i][j],dp[i-1][j-1] + 1);
}
for (int poz=1;poz<=n;poz++){
int i = poz, j = m, cnt = 0;
while (i > max(0,poz - n/2) && j >= 1){
if (a[i] == b[j]){
cnt++;
i--, j--;
} else {
if (dp[i][j-1] >= dp[i-1][j])
j--;
else i--;
}
}
sol = max (sol,cnt);
}
}
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];
for (i=1;i<=n;i++)
a[i+n] = a[i];
n *= 2;
solve (a,b);
solve (a,b2);
for (i=1;i<=n/2;i++)
a2[i+n/2] = a2[i];
solve (a2,b);
cout<<sol;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |