# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
357731 | nicolaalexandra | Round words (IZhO13_rowords) | C++14 | 2097 ms | 77484 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 4010
using namespace std;
char a[DIM],b[DIM],a2[DIM],b2[DIM];
int dp[DIM][DIM],t[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++){
if (dp[i][j-1] > dp[i][j]){
dp[i][j] = dp[i][j-1];
t[i][j] = 1;
}
if (a[i] == b[j] && dp[i-1][j-1] + 1 > dp[i][j]){
dp[i][j] = dp[i-1][j-1] + 1;
t[i][j] = 2;
}
if (dp[i-1][j] > dp[i][j]){
dp[i][j] = dp[i-1][j];
t[i][j] = 3;
}
}
for (int poz=n+1;poz<=2*n;poz++){
/// sterg - n u s t i u s a f a c a s t a a j u t o r
i = poz - n, j = 1;
for (j=1;j<=m;j++)
dp[i][j] = 0;
for (i=poz-n+1;i<poz;i++)
for (j=1;j<=m;j++){
dp[i][j] = 0;
if (dp[i][j-1] > dp[i][j]){
dp[i][j] = dp[i][j-1];
t[i][j] = 1;
}
if (a[i] == b[j] && dp[i-1][j-1] + 1 > dp[i][j]){
dp[i][j] = dp[i-1][j-1] + 1;
t[i][j] = 2;
}
if (dp[i-1][j] > dp[i][j]){
dp[i][j] = dp[i-1][j];
t[i][j] = 3;
}
}
/// adaug
i = poz;
for (j=1;j<=m;j++){
if (dp[i][j-1] > dp[i][j]){
dp[i][j] = dp[i][j-1];
t[i][j] = 1;
}
if (a[i] == b[j] && dp[i-1][j-1] + 1 > dp[i][j]){
dp[i][j] = dp[i-1][j-1] + 1;
t[i][j] = 2;
}
if (dp[i-1][j] > dp[i][j]){
dp[i][j] = dp[i-1][j];
t[i][j] = 3;
}
}
sol = max (sol,dp[poz][m]);
}
}
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];
solve (a,b);
solve (a,b2);
for (i=1;i<=n;i++)
a2[i+n] = a2[i];
solve (a2,b);
cout<<sol;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |