cp_library

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

View the Project on GitHub downerkei/cp_library

:heavy_check_mark: verify/yosupo/yosupo_enumerate_palindromes.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_palindromes"

#include <bits/stdc++.h>
using namespace std;

#include "../../string/manacher.hpp"

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;

    string T;
    for(int i = 0; i < S.size(); i++) {
        T += '$';
        T += S[i];
    }
    T += '$';

    auto ans = manacher(T);
    for(int i = 1; i < ans.size() - 1; i++) {
        cout << ans[i] - 1 << " ";
    }
    cout << "\n";

    return 0;
}
#line 1 "verify/yosupo/yosupo_enumerate_palindromes.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/enumerate_palindromes"

#include <bits/stdc++.h>
using namespace std;

#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;
}
#line 7 "verify/yosupo/yosupo_enumerate_palindromes.test.cpp"

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;

    string T;
    for(int i = 0; i < S.size(); i++) {
        T += '$';
        T += S[i];
    }
    T += '$';

    auto ans = manacher(T);
    for(int i = 1; i < ans.size() - 1; i++) {
        cout << ans[i] - 1 << " ";
    }
    cout << "\n";

    return 0;
}
Back to top page