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>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;
int main() {
cin.sync_with_stdio(false);
string a, b;
cin >> a >> b;
ll ans = 0;
ll pos1, pos2;
vector<vector<ll>> v(3001, vector<ll>(3001));
rep(i, 0, b.size()) {
ll counter = 0;
rep(j, 1, a.size()+1) {
if (b[i+counter] == a[j-1])v[i][j] = ++counter;
else {
while (b[i + counter] != a[j - 1] && counter)counter--;
if (b[i + counter] == a[j - 1])v[i][j] = ++counter;
}
}
}
rep(i, 0, a.size()) {
ll counter = 0;
rep(j, 1, b.size() + 1) {
if (a[i + counter] == b[j-1])counter++;
else {
while (a[i + counter] != b[j - 1] && counter)counter--;
if (a[i + counter] == b[j - 1])++counter;
}
if (ans < counter + v[j][i]) {
ans = counter + v[j][i];
pos1 = i - v[j][i];
pos2 = j - counter;
}
}
}
reverse(all(a));
v.clear();
v.resize(3001, vector<ll>(3001, 0));
rep(i, 0, b.size()) {
ll counter = 0;
rep(j, 1, a.size() + 1) {
if (b[i + counter] == a[j - 1])v[i][j] = ++counter;
else {
while (b[i + counter] != a[j - 1]&&counter)counter--;
if (b[i + counter] == a[j - 1])v[i][j] = ++counter;
}
}
}
rep(i, 0, a.size()) {
ll counter = 0;
rep(j, 1, b.size() + 1) {
if (a[i + counter] == b[j - 1])counter++;
else {
while (a[i + counter] != b[j - 1] && counter)counter--;
if (a[i + counter] == b[j - 1])counter++;
}
if (ans < counter + v[j][i]) {
ans = counter + v[j][i];
pos1 = a.size()-i - counter;
pos2 = j - counter;
}
}
}
cout << ans << endl;
if (ans)cout << pos1 << " " << pos2;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |