#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];
void solve() {
cin >> a >> b;
n = a.size();
m = b.size();
mod = 1e9+7;
pw[0] = 1;
pw[1] = 1e4+7;
for(int i = 2; i < max(n,m); i++) {
pw[i] = pw[i-1]*pw[1]%mod;
}
map<int,vector<int>> sta,eda;
int ansa, ansb, ans = 0;
for(int i = 0; i < n; i++) {
int cur = 0;
for(int j = i; j < n; j++) {
cur+= (a[j])*pw[j-i]; cur%= mod;
// It exist one cur that starts in
sta[cur].pb(i);
eda[cur].pb(j);
// cout << " " << i << " " << j << " " << cur << endl;
}
}
for(int i = 0; i < m; i++) {
int cur = 0;
for(int j = i; j < m; j++) {
cur+= (b[j])*pw[j-i]; cur%= mod;
//comecando em i
// if(eda.count(cur)) {
// if(j-i+1 > ans) {
// ans = j-i+1;
// ansa = eda[cur][0]-j+i;
// ansb = i;
// }
// }
if(sta.count(cur)) {
if(j-i+1 > ans) {
ans = j-i+1;
ansa = sta[cur][0];
ansb = i;
}
}
}
}
reverse(all(b));
for(int i = 0; i < m; i++) {
int cur = 0;
for(int j = i; j < m; j++) {
cur+= (b[j])*pw[j-i]; cur%= mod;
//comecando em i
// if(eda.count(cur)) {
// if(j-i+1 > ans) {
// ans = j-i+1;
// ansa = eda[cur][0]-j+i;
// ansb = i;
// cout << i << " " << j << " " << cur << endl;
// }
// }
if(sta.count(cur)) {
if(j-i+1 > ans) {
ans = j-i+1;
ansa = sta[cur][0];
ansb = m-j-1;
// cout << i << " " << j << " " << cur << endl;
}
}
}
}
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 |
Partially correct |
2 ms |
724 KB |
Output is partially correct |
2 |
Partially correct |
3 ms |
724 KB |
Output is partially correct |
3 |
Partially correct |
3 ms |
836 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
1092 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
1364 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
724 KB |
Output is partially correct |
2 |
Partially correct |
3 ms |
724 KB |
Output is partially correct |
3 |
Partially correct |
3 ms |
836 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
1092 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
1364 KB |
Output is partially correct |
6 |
Partially correct |
36 ms |
4448 KB |
Output is partially correct |
7 |
Partially correct |
59 ms |
7492 KB |
Output is partially correct |
8 |
Incorrect |
124 ms |
15364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
724 KB |
Output is partially correct |
2 |
Partially correct |
3 ms |
724 KB |
Output is partially correct |
3 |
Partially correct |
3 ms |
836 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
1092 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
1364 KB |
Output is partially correct |
6 |
Partially correct |
36 ms |
4448 KB |
Output is partially correct |
7 |
Partially correct |
59 ms |
7492 KB |
Output is partially correct |
8 |
Incorrect |
124 ms |
15364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |