Algorithms from an Algorithmic Winter Training Camp

Balanced String Analysis (Simple and Extended) Problem Statement We need to analyze strings composed of 0, 1, and ?. The question marks can be replaced with either 0 or 1. The goal is to compute how many valid configurations result in "balanced" strings according to a specific criterion. Simple Approach For small lengths, a brute-forc ...

Posted on Mon, 18 May 2026 05:19:55 +0000 by dodgyJim

LeetCode 62: Unique Paths (Dynamic Programming, Combinatorics)

Problem Description A robot is located at the top - left corner of an m x n grid (marked 'Start'). The robot can only move either down or right at any point. The goal is to reach the bottom - right corner (marked 'Finish'). We need to determine the number of unique paths possible. Examples Example 1: Input: rows = 3, cols = 7 Output: 28 Exampl ...

Posted on Sat, 16 May 2026 05:47:43 +0000 by ansarka

AtCoder Regular Contest 104 Problem Solutions

Problem A: Plus Minus Given the sum and difference of two numbers, we can easily retrieve the original values. The first number is the average of the sum and difference, while the second is half of the difference subtracted from the sum. s, d = map(int, input().split()) print((s + d) // 2, (s - d) // 2) Problem B: DNA Sequence A substring is c ...

Posted on Fri, 15 May 2026 00:15:36 +0000 by ganich

Competitive Programming Problem Analysis: Diverse Algorithmic Challenges

This document presents an analysis of several competitive programming problems, outlining their descriptions, solution approaches, and specific implementation details or common pitfalls encountered. The problems cover various domains including number theory, combinatorics, geometry, and dynamic programming. Problem 1: Minimizing Sum with Given ...

Posted on Thu, 14 May 2026 14:05:51 +0000 by cash09

Tree Coloring Problem Solution Using Fast Fourier Transform

This problem involves calculating valid colorings of a tree under certain constraints. The solution uses inclusion-exclution principle combined with polynomial multiplication via Number Theoretic Transform (NTT). Basic Approach We approach the problem by computing the complement: count arrangements where at least one node violates the coloring ...

Posted on Thu, 14 May 2026 08:51:57 +0000 by Kitara

Ambiguous Coordinate Generation Algorithm

Problem Analysis Given a string containing only digits within parentheses, the task is to generate all valid coordinate pairs that could have produced the original string when punctuation was removed. The coordinates must adhere to specific formatting rules: no leading or trailing zeros in decimal components, and decimal points must be preceded ...

Posted on Wed, 13 May 2026 14:32:49 +0000 by nevynev

Lucas Theorem and Its Extended Application

Lucas Theorem Mathematical Statement Given prime $p$, the following congruence holds: $$\binom{n}{m} \equiv \binom{\lfloor n/p \rfloor}{\lfloor m/p \rfloor} \cdot \binom{n \bmod p}{m \bmod p} \pmod{p}$$ Proof Foundation Lemma 1 For prime $p$: $$\binom{p}{k} \equiv 0 \pmod{p} \text{ when } 0 < k < p$$ The numerator contains factor $p$, mak ...

Posted on Tue, 12 May 2026 18:23:17 +0000 by Moneypenny

The Inclusion-Exclusion Principle: Applications in Competitive Programming

The Inclusion-Exclusion Principle The Inclusion-Exclusion Principle is a fundamental concept in combinatorics that provides a method for calculating the size of the union of multiple sets. It addresses the problem of avoiding overcounting elements that belong to multiple sets by systematically accounting for intersections. Codeforces 547C: Mi ...

Posted on Tue, 12 May 2026 15:12:06 +0000 by aouriques

Algorithmic Techniques for AtCoder Beginner Contest 042: Sorting, Combinatorics, and Constraint Satisfaction

Problem A: Numerical Triplet Verification Determine whether a sequence of three integers strictly consists of two fives and one seven. Ordering the inputs simplifies validation. Applying an ascending sort arranges the values sequentially, allowing a direct equality check against the target pattern. This approach eliminates conditional branching ...

Posted on Tue, 12 May 2026 14:59:17 +0000 by smartsley

Gale-Ryser Theorem: Bipartite Graph Degree Sequence Characterization

Consider two sequences of non-negative integers \(p_1 \ge p_2 \ge \dots \ge p_n\) and \(q_1 \ge q_2 \ge \dots \ge q_m\) satisfying \(\sum_{i=1}^n p_i = \sum_{i=1}^m q_i\). The Gale-Ryser theorem states that a simple bipartite graph exists with left vertices having degrees \(p_1, p_2, \dots, p_n\) and right vertices having degrees \(q_1, q_2, \d ...

Posted on Tue, 12 May 2026 14:27:29 +0000 by Steffen