#pragma once #include #include std::vector border_table(int n, const char *s) { std::vector nxt(n, -1); for (int i = 1; i < n; ++i) { auto &j = nxt[i] = i - 1; while (~j) { j = nxt[j]; if (s[j + 1] == s[i]) { j++; break; } } } return nxt; } std::vector border_table(const std::string &s) { return border_table(s.size(), s.c_str()); }