# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884798 | racoon23 | Round words (IZhO13_rowords) | C++17 | 2096 ms | 14116 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 endl '\n'
#define int long long
const int MOD = 1e9 + 7;
const int help = (1 << 11) - 1;
const int MAXN = 1e5;
int n;
vector<int>arr;
vector<int> adj[MAXN + 11];
int offSet = 1e5 + 1;
bool vis[MAXN + 12];
void dfs(int s) {
cout << s << " ";
for (auto child : adj[s]) {
if (vis[child] == 0) {
dfs(child);
}
}
vis[s] = 1;
}
int ans(int i, int j, string &a, string &b, vector<vector<int>>&dp) {
if (i >= a.size() | j >= b.size()) {
return 0;
}
if (dp[i][j] != -1)return dp[i][j];
if (a[i] == b[j]) {
return ans(i + 1, j + 1, a, b, dp) + 1;
}
return dp[i][j] = max(ans(i, j + 1, a, b, dp), ans(i + 1, j, a, b, dp));
}
int LCS(string&a, string&b) {
vector<vector<int>>dp(a.size(), vector<int>(b.size(), -1));
return ans(0, 0, a, b, dp);
}
string left(int i, string &a) {
string ret = "";
// ret.push_back
for (int j = i; j >= 0; j--)ret.push_back(a[j]);
for (int j = a.size() - 1; j > i; j--)ret.push_back(a[j]);
return ret;
}
string right(int i, string& a) {
string ret = "";
// ret.push_back
for (int j = i; j < a.size(); j++)ret.push_back(a[j]);
for (int j = 0; j < i; j++)ret.push_back(a[j]);
return ret;
}
void solve() {
string a, b;
cin >> a >> b;
int ans2 = 0;
string l, r;
for (int rot = 0; rot < a.size(); rot++) {
l = left(rot, a);
r = right(rot, a);
ans2 = max(ans2, max(LCS(l, b), LCS(r, b)));
}
cout << ans2 << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
int tt = 1;
//cin>>tt;
while (tt--) {
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |