algo — C++23 日本語リファレンス GitHub

test/aoj/challenge/2934.test.cpp

AC · 最終更新 2026-07-24 · GitHub

問題: https://onlinejudge.u-aizu.ac.jp/problems/2934

依存するヘッダ(1)
実装
// competitive-verifier: PROBLEM https://onlinejudge.u-aizu.ac.jp/problems/2934
#include <iostream>
#include <string>
#include "string/manacher.hpp"

int solve(const std::string &s) {
    int n = s.size();
    if (n == 1) return 1;
    Manacher manacher(s);
    for (int m = 1; m < n; ++m) {
        bool flag = true;
        int k = m;
        while (k < n) {
            flag &= manacher[k] >= std::min(m + 1, n - k);
            k += m;
        }
        if (flag) return m + 1;
    }
    return n;
}

int main(void) {
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    std::cout << solve(s) << '\n';

    return 0;
}