#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 3030;
string a,b;
int n, m, mod, pw[maxn], lra[maxn][maxn], lrb[maxn][maxn];
void solve() {
cin >> a >> b;
n = a.size();
m = b.size();
mod = 1e9+7;
pw[0] = 1;
pw[1] = 1e4+9;
for(int i = 2; i <= max(n,m); i++) {
pw[i] = pw[i-1]*pw[1]%mod;
}
map<int,int> st;
for(int i = 0; i < n; i++) {
int cur = 0;
for(int j = i; j < n; j++) {
cur = (cur+a[j]*pw[j-i])%mod;
lra[i][j] = cur;
st[cur] = i;
}
}
for(int i = 0; i < m; i++) {
int cur = 0;
for(int j = i; j < m; j++) {
cur = (cur+b[j]*pw[j-i])%mod;
lrb[i][j] = cur;
}
}
int ans = 0;
int ansa,ansb;
for(int i = 0; i < m; i++) {
for(int j = i; j < m; j++) {
for(int k = j; k < m; k++) {
//(j,k) (i,j-1)
int val = lrb[j][k]+ lrb[i][j-1]*pw[k-j+1];
val%= mod;
if(st.count(val) && k-i+1 > ans) {
ans = k-i+1;
ansa = st[val];
ansb = i;
}
}
}
}
reverse(all(b));
for(int i = 0; i < m; i++) {
int cur = 0;
for(int j = i; j < m; j++) {
cur = (cur+b[j]*pw[j-i])%mod;
lrb[i][j] = cur;
}
}
for(int i = 0; i < m; i++) {
for(int j = i; j < m; j++) {
for(int k = j; k < m; k++) {
//(j,k) (i,j-1)
int val = lrb[j][k]+ lrb[i][j-1]*pw[k-j+1];
val%= mod;
if(st.count(val) && k-i+1 > ans) {
ans = k-i+1;
ansa = st[val];
ansb = m-k-1;
}
}
}
}
cout << ans << endl;
cout << ansa << " " << ansb << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1340 KB |
Output is correct |
2 |
Correct |
28 ms |
1236 KB |
Output is correct |
3 |
Correct |
28 ms |
1336 KB |
Output is correct |
4 |
Correct |
20 ms |
1364 KB |
Output is correct |
5 |
Incorrect |
34 ms |
1492 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1340 KB |
Output is correct |
2 |
Correct |
28 ms |
1236 KB |
Output is correct |
3 |
Correct |
28 ms |
1336 KB |
Output is correct |
4 |
Correct |
20 ms |
1364 KB |
Output is correct |
5 |
Incorrect |
34 ms |
1492 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1340 KB |
Output is correct |
2 |
Correct |
28 ms |
1236 KB |
Output is correct |
3 |
Correct |
28 ms |
1336 KB |
Output is correct |
4 |
Correct |
20 ms |
1364 KB |
Output is correct |
5 |
Incorrect |
34 ms |
1492 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |