#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
vector <int> z_function(string s) {
int n = sz(s);
vector <int> z(n);
for (int i = 1, l = 0, r = 0; i < n; i++) {
if (i <= r)
z[i] = min (r - i + 1, z[i - l]);
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
z[i]++;
if (i + z[i] - 1 > r)
l = i, r = i + z[i] - 1;
}
return z;
}
void solve() {
string s, t;
cin >> s >> t;
int ans = 0, inds = -1, indt = -1;
vector <vector <int>> Z(sz(s));
for (int i = 0; i < sz(s); i++) {
string tmp = s + '$' + t;
Z[i] = z_function(tmp);
rotate(s.begin(), s.begin() + 1, s.end());
}
for (int i = 0; i < sz(s); i++) {
for (int j = sz(s) + 1; j < sz(s) + sz(t) + 1; j++) {
if (Z[i][j] == 0) continue;
int nxt = (i + Z[i][j]) % sz(s);
for (int k = sz(s) + 1; k < j; k++) {
if (Z[nxt][k] == j - k && Z[i][j] + Z[nxt][k] > ans) {
ans = Z[i][j] + Z[nxt][k];
inds = i; indt = k - sz(s) - 1;
}
}
}
}
reverse(all(t));
for (int i = 0; i < sz(s); i++) {
string tmp = s + '$' + t;
Z[i] = z_function(tmp);
rotate(s.begin(), s.begin() + 1, s.end());
}
for (int i = 0; i < sz(s); i++) {
for (int j = sz(s) + 1; j < sz(s) + sz(t) + 1; j++) {
if (Z[i][j] == 0) continue;
int nxt = (i + Z[i][j]) % sz(s);
for (int k = sz(s) + 1; k < j; k++) {
if (Z[nxt][k] == j - k && Z[i][j] + Z[nxt][k] > ans) {
ans = Z[i][j] + Z[nxt][k];
inds = i; indt = sz(t) - (k - sz(s) + ans - 2) - 1;
}
}
}
}
cout << ans << endl;
cout << inds << ' ' << indt << endl;
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
35 ms |
1588 KB |
Output is correct |
7 |
Correct |
17 ms |
1492 KB |
Output is correct |
8 |
Incorrect |
34 ms |
1364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
35 ms |
1588 KB |
Output is correct |
7 |
Correct |
17 ms |
1492 KB |
Output is correct |
8 |
Incorrect |
34 ms |
1364 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |