| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 444822 | prvocislo | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 700 ms | 584 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>
typedef long long ll;
using namespace std;
void pf_function(const string &s, vector<int> &p)
{
    p.resize(s.size());
    p[0] = 0;
    for (int i = 1; i < s.size(); i++)
    {
        int j = p[i-1];
        while (j && s[i] != s[j]) j = p[j-1];
        if (s[i] == s[j]) j++;
        p[i] = j;
    }
    /*cout << "\n" << s << "\n";
    for (int i = 0; i < p.size(); i++) cout << p[i] << " ";
    cout << endl;*/
}
vector<int> best(const string &s, const string &t, bool rv)
{
    int n = s.size(), m = t.size();
    vector<int> ans = {0, 0, 0};
    for (int i = 0; i < n; i++) // skusime kde rozrezat s
    {
        //cout << i << endl;
        string s1 = s.substr(0, i), s2 = s.substr(i, n-i);
        string t1 = t;
        reverse(t1.begin(), t1.end()), reverse(s1.begin(), s1.end());
        vector<int> v1, v2;
        pf_function(s1 + "#" + t1, v1);
        pf_function(s2 + "#" + t, v2);
        for (int j = 0; j < m; j++)
        {
            int a = v1[v1.size() - j - 1], b = v2[s2.size() + j];
            int si = i - a, ti = j - b;
            if (rv) ti = m - (ti+a+b-1) - 1;
            ans = max(ans, {a+b, si, ti});
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    vector<int> ans = best(s, t, false);
    reverse(t.begin(), t.end());
    ans = max(ans, best(s, t, true));
    cout << ans[0] << "\n" << ans[1] << " " << ans[2] << "\n";
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
