#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 6e3 + 7;
const ll oo = 1e18 + 69;
string a[2];
int kmp[2][maxn], n, m;
void calc(int id, string s, string t) {
s = s + '.' + t;
kmp[id][0] = 0;
int j = 0;
for(int i = 1; i < Size(s); i++) {
while(j > 0 && s[i] != s[j]) j = kmp[id][j - 1];
j += (s[i] == s[j]);
kmp[id][i] = j;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
cin>>a[0]>>a[1];
n = Size(a[0]);
m = Size(a[1]);
int ans = 0, x = 0, y = 0;
for(int t = 0; t < 2; t++) {
for(int i = 0; i < n - 1; i++) {
calc(1, a[0].substr(i + 1, n - i - 1), a[1]);
string st = a[0].substr(0, i + 1);
reverse(all(st));
reverse(all(a[1]));
calc(0, st, a[1]);
reverse(all(a[1]));
for(int j = 0; j < m - 1; j++) {
if(maxi(ans, kmp[1][j + n - i] + kmp[0][m - j + i])) {
x = (t == 0 ? i - kmp[0][m - j + i] + 1:n - i - 1 - kmp[1][j + n - i]);
y = j - kmp[1][j + n - i] + 1;
}
}
}
reverse(all(a[0]));
}
cout<<ans<<"\n";
cout<<x<<" "<<y<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
319 ms |
856 KB |
Output is correct |
2 |
Correct |
269 ms |
568 KB |
Output is correct |
3 |
Correct |
336 ms |
580 KB |
Output is correct |
4 |
Correct |
253 ms |
604 KB |
Output is correct |
5 |
Correct |
209 ms |
576 KB |
Output is correct |
6 |
Correct |
222 ms |
624 KB |
Output is correct |
7 |
Correct |
249 ms |
604 KB |
Output is correct |
8 |
Correct |
274 ms |
592 KB |
Output is correct |
9 |
Correct |
285 ms |
852 KB |
Output is correct |