cp_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub downerkei/cp_library

:heavy_check_mark: string/manacher.hpp

Verified with

Code

vector<int> manacher(const string& s) {
    int n = s.size();
    vector<int> ret(n);
    int i = 0, j = 0;
    while(i < n) {
        while(i - j >= 0 && i + j < n && s[i - j] == s[i + j]) j++;
        ret[i] = j;
        int k = 1;
        while(i - k >= 0 && k + ret[i - k] < j) ret[i + k] = ret[i - k], k++;
        i += k; j -= k;
    }
    return ret;
}
#line 1 "string/manacher.hpp"
vector<int> manacher(const string& s) {
    int n = s.size();
    vector<int> ret(n);
    int i = 0, j = 0;
    while(i < n) {
        while(i - j >= 0 && i + j < n && s[i - j] == s[i + j]) j++;
        ret[i] = j;
        int k = 1;
        while(i - k >= 0 && k + ret[i - k] < j) ret[i + k] = ret[i - k], k++;
        i += k; j -= k;
    }
    return ret;
}
Back to top page