# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
339776 | beksultan04 | Round words (IZhO13_rowords) | C++14 | 2091 ms | 16492 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>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
const int N = 3e5+12,INF=100500;
int q[N],n,m;
int dp[2001][2001];
int fun(string &a,string &b){
int i,j;
for (i=1;i<=n;++i){
for (j=1;j<=m;++j){
dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
if (a[i-1]==b[j-1]){
dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
}
}
}
ret dp[n][m];
}
void rev(string &a){
a.pb(a[0]);
a.erase(a.begin());
}
main(){
string a,b;
cin>>a>>b;
n = a.size();m = b.size();
int ans = fun(a,b),i,j;
for (i=0;i<n;++i){
rev(a);
for (j=0;j<m;++j){
rev(b);
ans = max(ans,fun(a,b));
}
}
cout <<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |