#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int PRI = 41;
const int MOD = 2000000011;
int mul(int a, int b) {
return (1LL * a * b) % MOD;
}
int add(int a, int b) {
return (0LL + a + b) % MOD;
}
int hasher(string s) {
int res = 0;
for(int i = 0; i < int(s.size()); i++) {
res = mul(res, PRI);
res = add(res, (s[i] - 'a' +1));
}
return res;
}
int revhasher(string s) {
int res = 0;
for(int i = int(s.size()) -1; i >= 0; i--) {
res = mul(res, PRI);
res = add(res, (s[i] - 'a' +1));
}
return res;
}
int stra[405][405], strb[405][405];
int reva[405][405], revb[405][405];
#define ONLINE_JUDGE
void solve() {
string a, b;
cin >> a >> b;
int n = int(a.size()), m = int(b.size());
for(int len = n; len >= 1; len--) {
for(int l = 0; l + len -1 < n; l++) {
stra[l][l + len -1] = hasher(a.substr(l, len));
}
}
for(int len = m; len >= 1; len--) {
for(int l = 0; l + len -1 < m; l++) {
strb[l][l + len -1] = hasher(b.substr(l, len));
}
}
for(int len = n; len >= 1; len--) {
for(int l = 0; l + len -1 < n; l++) {
reva[l][l + len -1] = revhasher(a.substr(l, len));
}
}
for(int len = min(n, m); len >= 1; len--) {
for(int l = 0; l + len -1 < n; l++) {
for(int r = 0; r + len -1 < m; r++) {
for(int k = 0; k <= len; k++) {
//string x = a.substr(l, len);
//reverse(x.begin(), x.end());
//cerr << len << " -> " << x.substr(0, k) << " " << b.substr(r + len - k, k) << " :: " << x.substr(k, len - k) << " " << b.substr(r, len - k) << "\n";
//cerr << len << " -> " << reva[l][l + k -1] << " " << strb[r][r + k -1] << " :: " << reva[l + k][l + len -1] << " " << strb[r + k][r + len - 1] << "\n";
if(reva[l][l + k -1] == strb[r][r + k -1] && reva[l + k][l + len -1] == strb[r + k][r + len -1]) {
cout << len << "\n";
cout << l << " " << r << "\n";
return;
}
//cerr << len << " -> " << a.substr(l, k) << " " << b.substr(r + len - k, k) << " :: " << a.substr(l + k, len - k) << " " << b.substr(r, len - k) << "\n";
if(stra[l][l + k -1] == strb[r][r + k -1] && stra[l + k][l + len -1] == strb[r + k][r + len -1]) {
cout << len << "\n";
cout << l << " " << r << "\n";
return;
}
}
}
}
}
cout << 0 << "\n";
cout << 0 << " " << 0 << "\n";
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Partially correct |
13 ms |
2396 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Partially correct |
13 ms |
2396 KB |
Output is partially correct |
6 |
Correct |
296 ms |
2824 KB |
Output is correct |
7 |
Partially correct |
406 ms |
2644 KB |
Output is partially correct |
8 |
Correct |
1228 ms |
2816 KB |
Output is correct |
9 |
Execution timed out |
1517 ms |
2640 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2396 KB |
Output is correct |
2 |
Correct |
5 ms |
2396 KB |
Output is correct |
3 |
Correct |
6 ms |
2396 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Partially correct |
13 ms |
2396 KB |
Output is partially correct |
6 |
Correct |
296 ms |
2824 KB |
Output is correct |
7 |
Partially correct |
406 ms |
2644 KB |
Output is partially correct |
8 |
Correct |
1228 ms |
2816 KB |
Output is correct |
9 |
Execution timed out |
1517 ms |
2640 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |