Manacher's Algorithm and AC Automaton: Linear-Time Palindromes and Multi-Pattern Matching
Manacher's Algorithm
Purpose
Manacher's algorithm computes the longest palindromic substring centered at each position (including positions between characters for even-length palindromes) in O(n) time complexity.
Naive Approach
The naive method examines each center position and attempts to expand outward character by character until the charact ...
Posted on Sat, 19 Sep 2026 16:16:48 +0000 by Mathy
Resolving ValueError: prefix_allowed_tokens_fn Returned Empty List in HuggingFace Transformers
When using the transformers library for text generation with the prefix_allowed_tokens_fn parameter to constrain model outputs, a specific error may appear intermittently:
ValueError: prefix_allowed_tokens_fn returned an empty list for batch ID 0. This means that the constraint is unsatisfiable. Please check your implementation of prefix_allow ...
Posted on Sat, 12 Sep 2026 16:42:48 +0000 by ace21
National Day Simulation Contest Solutions
T1
This is a straightforward problem. Key reminder: read the problem carefully! Simpler problems are prone to errors.
T2
This is a straightforward problem. Greedy algorithms or dynamic programming can be used.
T3
Tip: When dealing with averages, subtract the average from all numbers and find subarrays with sum zero. Since the value range is sma ...
Posted on Sat, 12 Sep 2026 16:27:13 +0000 by hossein2kk
Efficient Calculation of String Sorting Distance Using Tries and 2D Range Queries
Problem Definition
Given $n$ strings $T_1, T_2, \dots, T_n$, each of length $len$. Define $f(a, b)$ as the minimum number of sorting operations required on substrings of $a$ to make it identical to $b$. If it is impossible to transform $a$ into $b$ via substring sorting, $f(a, b) = 1337$. The objective is to compute:
Analysis of Function Value ...
Posted on Mon, 07 Sep 2026 16:43:49 +0000 by ninedoors
Optimizing String and Array Problems with Greedy Algorithms and Data Structures
Problem 1: Lexicographical String Matching
Solution
Since the problem involves lexicographical order, a trie data structure is suitable.
To find the solution, use a greedy approach. Determine if the string ending at the current node is the answer. If not, continue to traverse to one of the child nodes. The process is illustrated in the followi ...
Posted on Wed, 02 Sep 2026 16:37:10 +0000 by corbin
Efficient Algorithms for Range Queries, Matrix Exponentiation, Trie DFS, and Subset Sum with Modular Arithmetic
Problem T1: Maximum Cross-Shaped Area in a Grid
Given a binary grid where '.' represents a valid cell and other characters are blocked, compute the largest cross-shaped region centered at any valid cell. A cross is defined by a vertical segment of height h and a horizontal segment of width w, both centered at the same point, with the total peri ...
Posted on Wed, 26 Aug 2026 16:40:14 +0000 by ricerocket
Educational Codeforces Round 157 Div. 2: Virtual Contest Analysis
Problem A: Treasure Chest
We need to calculate the minimum time to reach the chest and return to the start, given the ability to pull the chest towards the key for a maximum distance of k. There are two scenarios based on the relative positions of the chest pos_chest and the key pos_key:
If pos_key <= pos_chest: We pickup the key on the way ...
Posted on Mon, 17 Aug 2026 16:45:03 +0000 by vicodin
Trie Data Structure for Efficient String Matching and Filtering
Trie, also known as a prefix tree, is a tree-like data structure that stores strings by sharing common prefixes among them. This design optimizes space usage when handling sets of strings with overlapping beginnings.
For instance, strings "abc" and "abd" share the prefix "ab," allowing a single path for "ab&qu ...
Posted on Thu, 13 Aug 2026 16:12:01 +0000 by raptorman
Algorithmic Solutions: Interval Partitioning, Graph Matching, and Trie-Based Set Operations
Problem A: Large-Scale Simulation
A pure simulation problem centered on game theory mechanics. The implementation involves directly modeling the described rules and state transitions.
Problem B: Maximum Total Range for k-Partition
Define the weight of a subarray as its range (maximum element minus minimum element). For each k from 1 to n, compu ...
Posted on Thu, 16 Jul 2026 16:19:13 +0000 by killfall
SM Training Camp Notes (2024.11.15 ~ 2024.11.29)
DAY0 (2024.11.15)
Finally arriving at the camp.
T2 GYM104787M
First, we define a replica connected component as a connected component formed by traversing only nodes with index greater than n. It's not hard to observe that a replica connected component (green nodes) connects to several leaves with index less than n, and together with the origin ...
Posted on Fri, 10 Jul 2026 17:44:56 +0000 by raffael3d