This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub tatyam-prime/ICPC_notebook
#include "src/string/KMP.hpp"
vector<ll> KMP(string s)
$O(n)$ 時間
// kmp[i] := max{ l ≤ i | s[:l] == s[(i+1)-l:i+1] } // abacaba -> 0010123 auto KMP(string s) { vector<ll> p(sz(s)); rep(i, 1, sz(s)) { ll g = p[i - 1]; while(g && s[i] != s[g]) g = p[g - 1]; p[i] = g + (s[i] == s[g]); } return p; }
#line 1 "src/string/KMP.hpp" // kmp[i] := max{ l ≤ i | s[:l] == s[(i+1)-l:i+1] } // abacaba -> 0010123 auto KMP(string s) { vector<ll> p(sz(s)); rep(i, 1, sz(s)) { ll g = p[i - 1]; while(g && s[i] != s[g]) g = p[g - 1]; p[i] = g + (s[i] == s[g]); } return p; }