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

test/aoj/challenge/2763.test.cpp

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

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

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

std::string solve(const std::string &s) {
    int n = s.size();
    int x = n - knuth_morris_pratt(s)[n];
    int y = n + 1;
    while (!(y % x == 0 && y / x % 3 == 0)) ++y;
    int b = y - n;
    if (b * 2 > n - 3) return "mitomerarenaiWA";
    return "Love " + s.substr(0, y / 3) + "!";
}

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

    return 0;
}