Fading Coder

One Final Commit for the Last Sprint

Algorithmic Solution for Sequence Similarity Constraints via Suffix Automaton and Binary Lifting Union-Find

The problem requires counting the number of valid sequences \(b\) given constraints \(b_i \in [L_i, R_i]\) and a similarity condition defined by a sequence \(a\). Two sequences \(a\) and \(b\) are defined as "k-similar" if, for every quadruple \((l_1, r_1, l_2, r_2)\) where the intervals \([l_1, r_1...

String Algorithm Fundamentals: Border Theory, Z-Function, and Palindrome Automata

Prefix Function (KMP) The prefix function (also called failure function or pi function) measures the longest proper prefix that is also a suffix for each position. Here's an iterative computation: int pi[1000005]; void computePrefix(char* s, int n) { for (int i = 2; i <= n; i++) { int j = pi[i-1]...

Computing Unique Minimal Prefixes for a Set of Words

Givan a colection of words, the objective is to detremine the shortest unique prefix for each word. A prefix is a substring starting from the first character. For instance, the word "carbon" has prefixes: "c", "ca", "car", "carb", "carbo",...