#include <bits/stdc++.h>
using namespace std;
const int N=2005;
int dp[N][N];
int n,m;
string a,b;
int solve(){
int ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i-1]==b[j-1]){
dp[i][j]=dp[i-1][j-1]+1;
}
else{
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
ans=max(ans,dp[i][j]);
}
}
return ans;
}
int32_t main() {
cin>>a>>b;
n=a.size();
m=b.size();
int ans=0;
for(int i=0;i<n;i++){
ans=max(ans,solve());
rotate(a.begin(),a.begin()+1,a.end());
}
reverse(a.begin(),a.end());
for(int i=0;i<n;i++){
ans=max(ans,solve());
rotate(a.begin(),a.begin()+1,a.end());
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
548 KB |
Output is correct |
3 |
Correct |
1 ms |
500 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
374 ms |
5724 KB |
Output is correct |
7 |
Execution timed out |
2051 ms |
8284 KB |
Time limit exceeded |
8 |
Execution timed out |
2067 ms |
8796 KB |
Time limit exceeded |
9 |
Execution timed out |
2040 ms |
8280 KB |
Time limit exceeded |
10 |
Execution timed out |
2053 ms |
8284 KB |
Time limit exceeded |
11 |
Execution timed out |
2047 ms |
10844 KB |
Time limit exceeded |
12 |
Execution timed out |
2037 ms |
10840 KB |
Time limit exceeded |
13 |
Execution timed out |
2016 ms |
10840 KB |
Time limit exceeded |
14 |
Execution timed out |
2055 ms |
10844 KB |
Time limit exceeded |
15 |
Execution timed out |
2052 ms |
10844 KB |
Time limit exceeded |
16 |
Execution timed out |
2015 ms |
10840 KB |
Time limit exceeded |
17 |
Execution timed out |
2100 ms |
10584 KB |
Time limit exceeded |
18 |
Execution timed out |
2039 ms |
11868 KB |
Time limit exceeded |
19 |
Execution timed out |
2013 ms |
8280 KB |
Time limit exceeded |
20 |
Execution timed out |
2084 ms |
10584 KB |
Time limit exceeded |
21 |
Execution timed out |
2036 ms |
8276 KB |
Time limit exceeded |
22 |
Execution timed out |
2036 ms |
9308 KB |
Time limit exceeded |
23 |
Execution timed out |
2040 ms |
10588 KB |
Time limit exceeded |
24 |
Execution timed out |
2053 ms |
10588 KB |
Time limit exceeded |
25 |
Execution timed out |
2020 ms |
12380 KB |
Time limit exceeded |