#include<stdio.h>
#define N 4002
void rev(char*s,int n){char t;for(int i=0;i*2<n;++i)t=s[i],s[i]=s[n-1-i],s[n-1-i]=t;}
int len(char*s){int z=0;while(s[z])++z;return z;}
void cpy(char*s,char*t,int n){while(n--)*s++=*t++;}
int hi(int a,int b){return a>b?a:b;}
char s[N],t[N];
int z,dp[N][N],n,m;
void shinlena()
{
cpy(s+1+n,s+1,n);cpy(t+1+m,t+1,m);
for(int i=1;i<=2*n;++i)for(int j=1;j<=2*m;++j)
dp[i][j]=hi(hi(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]+(s[i]==t[j]));
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)
z=hi(z,dp[i+n-1][j+m-1]-(dp[i][j]-(s[i]==t[j])));
}
int main()
{
scanf("%s%s",s+1,t+1);n=len(s+1),m=len(t+1);
shinlena();rev(s+1,n);shinlena();rev(t+1,m);shinlena();rev(s+1,n);shinlena();
printf("%d",z);
}
Compilation message
rowords.cpp: In function 'int main()':
rowords.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%s%s",s+1,t+1);n=len(s+1),m=len(t+1);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
612 KB |
Output is correct |
5 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
6 |
Incorrect |
8 ms |
9820 KB |
Output isn't correct |
7 |
Correct |
46 ms |
31836 KB |
Output is correct |
8 |
Incorrect |
40 ms |
31836 KB |
Output isn't correct |
9 |
Incorrect |
42 ms |
31836 KB |
Output isn't correct |
10 |
Incorrect |
44 ms |
31836 KB |
Output isn't correct |
11 |
Incorrect |
49 ms |
35936 KB |
Output isn't correct |
12 |
Incorrect |
55 ms |
38236 KB |
Output isn't correct |
13 |
Incorrect |
53 ms |
38236 KB |
Output isn't correct |
14 |
Incorrect |
49 ms |
36124 KB |
Output isn't correct |
15 |
Incorrect |
59 ms |
40340 KB |
Output isn't correct |
16 |
Incorrect |
47 ms |
34108 KB |
Output isn't correct |
17 |
Incorrect |
41 ms |
46172 KB |
Output isn't correct |
18 |
Incorrect |
54 ms |
48220 KB |
Output isn't correct |
19 |
Incorrect |
40 ms |
31832 KB |
Output isn't correct |
20 |
Incorrect |
48 ms |
42072 KB |
Output isn't correct |
21 |
Incorrect |
22 ms |
18004 KB |
Output isn't correct |
22 |
Incorrect |
25 ms |
21852 KB |
Output isn't correct |
23 |
Incorrect |
33 ms |
32860 KB |
Output isn't correct |
24 |
Incorrect |
36 ms |
34140 KB |
Output isn't correct |
25 |
Incorrect |
46 ms |
45400 KB |
Output isn't correct |