The Extended Euclidean Algorithm is a fundamental tool for solving linear Diophantine equations of the form ax + by = gcd(a, b). This technique is frequently required in competitive programming to solve problems involving modular arithmetic and periodic patterns, such as the classic "Frog's Mee...
Problem Set Overview This article presents solutions to five algorithmic problems from Meituan's 2024 Spring campus recruitment online assessment for software engineering positions. Each problem requires specific algorithmic techniques ranging from prefix sum optimization to union-find data structur...
This article presents concise, robust solutions to two distinct algorithmic problems from a competitive programming context: parsing and decoding HTTP-like header structures using Huffman tree reconstruction, and computing the minimum excluded value (MEX) on tree paths via persistent segment trees....
Problem Analysis This problem requires splitting and merging intervals with maximum profit. The solution naturally fits the interval dynamic programming paradigm. DP Formulation For any interval [l, r], we choose a split point j (where l ≤ j < r) and split it into two subintervals: [l, j] and [j+...
D. Prefix Reversal Construction A palindrome insertion strategy can transform any sequence by reversing prefixes. Inserting a pattern like abc...cba after a prefix abc... effectively reverses that prefix while leaving subsequent elements unchanged. Key insight: Two flip operations suffice for transf...
Data Structures Mo's Algorithm Standard Mo's Algorithm Used to solve problems like P1494 [National Training Team] Little Z's Socks. #include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 200010; struct Query { int l, r, idx; }; struct Fraction { int numerator, den...
Given an enteger grid of dimensions $R \times C$ ($R \leq 12$, $C \leq 2000$), the optimization objective is to assign disjoint subsets of row indices to a selected group of columns. Each assigned column may undergo an independent vertical cyclic shift. The contribution of a column to its allocated...
Solutions to CSP-S 2021 Programming Competition Problems Problem 1 Solution The problem involves resource allocation between two regions. If we precompute f₁, f₂, ..., fₘ₁ where fᵢ represents the maximum number of resources allocated to the domestic region with i resources, then fᵢ₊₁ will always inc...
Round 1 Problem: Basic ABC Exercise The problem asks to count pairs ((x, y)) that satisfy certain conditions. A key observation is that the process of filling characters can be modeled using a greedy strategy: always prefer longer strings when converting. The condition reduces to comparing counts of...
When processing identification strings composed of uppercase letters, a common pattern involves converting characters to numerical values and aggregating them through multiplication. Consider a scenario where two entities—a celestial object and a team—must be matched based on their respective name e...