# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1076699 | vjudge1 | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 199 ms | 568 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
#define lb(s, a) lower_bound(all(s), (a)) - s.begin()
using namespace std;
typedef long long ll;
const int ar = 2e5+2;
const ll mod = 1e9+7;
const int oo = 1e9;
vector<int> KMP(string s) {
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) {
int j = pi[i - 1];
while (j > 0 && s[i] != s[j])
j = pi[j - 1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "wefwe"
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int res = 0, l = 0, r = 0;
for(int type = 0; type < 2; ++type) {
reverse(all(s));
for(int i = 0; i < n; ++i) {
string s1 = s.substr(0, i + 1), s2 = s.substr(i + 1, n - i - 1);
reverse(all(s1));
string tn = t;
reverse(all(tn));
vector <int> kmp1 = KMP(s1 + "/" + tn), kmp2 = KMP(s2 + "/" + t);
for(int j = 0; j < m; ++j) {
if(res < kmp1[i + m - j] + kmp2[j + n - i]) {
res = kmp1[i + m - j] + kmp2[j + n - i];
if(type == 0) l = n - i - 1 - kmp2[j + n - i];
else l = i + 1 - kmp1[i + m - j];
r = j - kmp2[j + n - i] + 1;
}
}
}
}
cout << res << '\n' << l << ' ' << r;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |