Submission #974999

# Submission time Handle Problem Language Result Execution time Memory
974999 2024-05-04T09:27:59 Z Mighilon Necklace (Subtask 4) (BOI19_necklace4) C++17
15 / 15
200 ms 848 KB
#include <bits/stdc++.h>
using namespace std;
 
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
// #define cin fin
// #define cout fout
// const string FILE_NAME = ""; ifstream fin(FILE_NAME + ".in"); ofstream fout(FILE_NAME + ".out");
#endif
 
typedef long long ll;
// typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
// typedef vector<pl> vpl; 
 
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first 
#define s second
#define pb push_back
// #define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
 
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int mxN = 1e7;

int p1[6001], p2[6001];

void fill_p(string s, int *p){
    for(int i = 1, j = 0; i < (int)s.size(); ++i){
        while(j > 0 && s[i] != s[j])
            j = p[j - 1];
        if(s[i] == s[j]) j++;
        p[i] = j;
    }
}

tuple<int, int, int> solve(string s, string t, bool rev){
    int n = s.size(), m = t.size();
    tuple<int, int, int> ans = {0, 0, 0};
    F0R(i, n){
        string s1 = s.substr(0, i), s2 = s.substr(i, n - i);
        reverse(all(s1));
        string t1 = t, t2 = t;
        reverse(all(t2));
        fill_p(s1 + "#" + t1, p1), fill_p(s2 + "#" + t2, p2);
        FOR(j, 1, m + 1){
            ans = max(ans, {p1[i + j] + p2[n + m - i - j], i - p1[i + j],
                    rev ? m - j - p2[n + m - i -j] : j - p1[i + j]});
        }
    }
    return ans;
}

void solve(){
    string s, t;
    cin >> s >> t;
    tuple<int, int, int> ans = solve(s, t, false);
    reverse(all(t));
    ans = max(ans, solve(s, t, true));
    cout << get<0>(ans) << nl << get<1>(ans) << " " << get<2>(ans);
}
 
int32_t main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int TC = 1;
    /* cin >> TC; */
    while(TC--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 191 ms 604 KB Output is correct
2 Correct 151 ms 604 KB Output is correct
3 Correct 200 ms 596 KB Output is correct
4 Correct 138 ms 600 KB Output is correct
5 Correct 143 ms 604 KB Output is correct
6 Correct 173 ms 848 KB Output is correct
7 Correct 157 ms 592 KB Output is correct
8 Correct 184 ms 576 KB Output is correct
9 Correct 180 ms 596 KB Output is correct