/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int L_MAX = 3000;
string a, b;
int n, m;
int lcp[L_MAX + 2][L_MAX + 2];
int kmp[L_MAX + 2][L_MAX + 2];
int lce[L_MAX + 2][L_MAX + 2];
vector <int> solve () {
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
lcp[i][j] = (a[i] == b[j] ? lcp[i + 1][j + 1] + 1 : 0);
}
}
for (int i = 0; i < n; i++) {
kmp[i][i] = 0;
for (int j = i + 1; j < n; j++) {
kmp[i][j] = kmp[i][j - 1];
while (kmp[i][j] > 0 && a[i + kmp[i][j]] != a[j]) {
kmp[i][j] = kmp[i][i + kmp[i][j] - 1];
}
if (a[i + kmp[i][j]] == a[j]) {
kmp[i][j]++;
}
}
}
for (int i = 0; i < n; i++) {
lce[i][0] = (a[i] == b[0] ? 1 : 0);
for (int j = 1; j < m; j++) {
lce[i][j] = lce[i][j - 1];
while (lce[i][j] > 0 && a[i + lce[i][j]] != b[j]) {
lce[i][j] = kmp[i][i + lce[i][j] - 1];
}
if (a[i + lce[i][j]] == b[j]) {
lce[i][j]++;
}
}
}
vector <int> best = {0, 0, 0};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int x = lcp[i][j];
int y = 0;
if (i + x < n && j - 1 >= 0) {
y = lce[i + x][j - 1];
}
vector <int> here = {x + y, i, j - y};
if (here[0] > best[0]) {
best = here;
}
}
}
return best;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
n = (int) a.size(); m = (int) b.size();
vector <int> best1 = solve();
reverse(b.begin(), b.end());
vector <int> best2 = solve();
best2[2] = m - best2[2] - best2[0];
if (best1[0] < best2[0]) {
swap(best1, best2);
}
cout << best1[0] << "\n";
cout << best1[1] << " " << best1[2] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
11 ms |
6724 KB |
Output is correct |
7 |
Correct |
10 ms |
6604 KB |
Output is correct |
8 |
Correct |
9 ms |
6300 KB |
Output is correct |
9 |
Correct |
11 ms |
6356 KB |
Output is correct |
10 |
Correct |
10 ms |
6660 KB |
Output is correct |
11 |
Correct |
10 ms |
6624 KB |
Output is correct |
12 |
Correct |
12 ms |
6356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1620 KB |
Output is correct |
2 |
Correct |
1 ms |
1620 KB |
Output is correct |
3 |
Correct |
1 ms |
1236 KB |
Output is correct |
4 |
Correct |
1 ms |
1620 KB |
Output is correct |
5 |
Correct |
2 ms |
1492 KB |
Output is correct |
6 |
Correct |
11 ms |
6724 KB |
Output is correct |
7 |
Correct |
10 ms |
6604 KB |
Output is correct |
8 |
Correct |
9 ms |
6300 KB |
Output is correct |
9 |
Correct |
11 ms |
6356 KB |
Output is correct |
10 |
Correct |
10 ms |
6660 KB |
Output is correct |
11 |
Correct |
10 ms |
6624 KB |
Output is correct |
12 |
Correct |
12 ms |
6356 KB |
Output is correct |
13 |
Correct |
483 ms |
98432 KB |
Output is correct |
14 |
Correct |
450 ms |
98552 KB |
Output is correct |
15 |
Correct |
493 ms |
94608 KB |
Output is correct |
16 |
Correct |
471 ms |
98076 KB |
Output is correct |
17 |
Correct |
420 ms |
96464 KB |
Output is correct |
18 |
Correct |
431 ms |
98056 KB |
Output is correct |
19 |
Correct |
456 ms |
97900 KB |
Output is correct |
20 |
Correct |
497 ms |
96460 KB |
Output is correct |
21 |
Correct |
491 ms |
97016 KB |
Output is correct |