#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)
{
if(dp[i][j]==1+dp[i-1][j-1])
z=hi(z,dp[i+n-1][j+m-1]-dp[i-1][j-1]);
else
{
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:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
6 |
Incorrect |
9 ms |
9820 KB |
Output isn't correct |
7 |
Correct |
46 ms |
32020 KB |
Output is correct |
8 |
Incorrect |
45 ms |
32048 KB |
Output isn't correct |
9 |
Incorrect |
47 ms |
31832 KB |
Output isn't correct |
10 |
Incorrect |
49 ms |
32044 KB |
Output isn't correct |
11 |
Incorrect |
54 ms |
36184 KB |
Output isn't correct |
12 |
Incorrect |
51 ms |
38232 KB |
Output isn't correct |
13 |
Incorrect |
63 ms |
38232 KB |
Output isn't correct |
14 |
Incorrect |
58 ms |
35932 KB |
Output isn't correct |
15 |
Incorrect |
65 ms |
40284 KB |
Output isn't correct |
16 |
Incorrect |
49 ms |
33884 KB |
Output isn't correct |
17 |
Incorrect |
45 ms |
46168 KB |
Output isn't correct |
18 |
Incorrect |
66 ms |
48392 KB |
Output isn't correct |
19 |
Incorrect |
47 ms |
32044 KB |
Output isn't correct |
20 |
Incorrect |
57 ms |
42192 KB |
Output isn't correct |
21 |
Incorrect |
19 ms |
18012 KB |
Output isn't correct |
22 |
Incorrect |
32 ms |
21852 KB |
Output isn't correct |
23 |
Incorrect |
39 ms |
32928 KB |
Output isn't correct |
24 |
Incorrect |
43 ms |
34140 KB |
Output isn't correct |
25 |
Incorrect |
53 ms |
45404 KB |
Output isn't correct |