brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104158J - High Jump

We are given a line of tiles, initially each tile has height 1. Over time, the heights only increase. Each operation selects a contiguous segment and adds the same value to every tile in that segment.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 27

Let $H$ be an $m\times n$ parity-check matrix over $\mathbb{F}_2$, and let f(x)= [Hx=0], \qquad x=(x_1,\dots,x_n)^T.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104158I - Drunk Coworker

We are given a quadratic curve that models a drunk coworker’s path across a rectangular room. At any horizontal position $x$, the coworker is located at height $f(x)$, where $f$ is a quadratic function.

codeforcescompetitive-programming
CF 104158H - Crapper's Collapse Catastrophe

We can think of the building as an infinite rooted structure starting from room 0. Each room generates new rooms in the level above it, but the branching factor depends on the parity of the room: even-indexed rooms expand into a rooms, and odd-indexed rooms expand into b rooms.

codeforcescompetitive-programming
CF 104158F - Toilet Orders

We are given pairs of large integers representing counts of two types of parts, bowls and lids. From each pair, the number of complete toilets Thomas can assemble is determined by the greatest common divisor of these two quantities.

codeforcescompetitive-programming
CF 104158G - Crappy Typing

We are given a queue of employees, each associated with a fixed typing duration. There are $N$ employees standing in order, and we can place $M$ computers in front of them. At time zero, the first $M$ employees each occupy one computer and start typing.

codeforcescompetitive-programming
CF 104158E - Brainless Brainstorming

We are given a sequence of $N$ time slots, each slot containing three independent offers: one from Jim, one from Dwight, and one from Kevin. In slot $i$, choosing Jim yields $ai$ ideas, Dwight yields $bi$, and Kevin yields $ci$.

codeforcescompetitive-programming
CF 104158C - Flush-tastic Throwing Challenge

We are given a circular target on a 2D plane and a set of points representing where employees throw an object. The task is to count how many of these points land inside or exactly on the boundary of the circle. Each throw is just a coordinate on the plane.

codeforcescompetitive-programming
CF 104158D - Speedy Stamping

We are given a target string consisting only of the characters T and C. The task is to count how many different ways this string can be formed using a fixed set of stamps. Each position in the string is produced by choosing one of four stamp types.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 267

Let $U=\{1,\dots,n\}$ with variable order $1<2<\cdots<n$.

taocpmathematicsalgorithmsvolume-4hm-hard
CF 104159H - Непростые отношения между числами

We are given a prefix of natural numbers from 1 up to some limit $n$, and we want to choose as many of them as possible under a single restriction.

codeforcescompetitive-programming
CF 104159G - Погоня, погоня, погоня

Two trucks move along a straight road made of five consecutive segments. Each segment has a fixed length, and two of these segments are “bad road” segments where movement becomes slower for both vehicles.

codeforcescompetitive-programming
CF 104159F - Wordland

We are given several short strings made of lowercase English letters. For each string, we need to decide whether it is “valid” under a rule that depends on how letters alternate between two classes: vowels and consonants. The rule is applied after a preprocessing step.

codeforcescompetitive-programming
CF 104159E - Верстовые столбы

We are given a positive integer $N$. We need to construct the smallest positive integer that satisfies two conditions at the same time: it must be divisible by $N$, and its decimal representation must end in the digit zero. Ending in zero means the number is a multiple of 10.

codeforcescompetitive-programming
CF 104160M - Vulpecula

We are given a tree of up to $n$ vertices, where each vertex represents a star. The tree is rooted implicitly by the input construction, but conceptually it is just an undirected tree defined by $n-1$ edges. For each star, Mu chooses it as a viewing center.

codeforcescompetitive-programming
CF 104160L - Tavern Chess

Two players build small combat teams, each consisting of at most seven units placed in a fixed left-to-right order. Every unit starts with a single attribute value, which simultaneously acts as its hit points and its attack power.

codeforcescompetitive-programming
CF 104160K - Security at Museums

We are given a simple polygon described by its vertices in counterclockwise order. On each vertex sits an object, and we want to count how many subsets of these vertices a group of thieves could choose, under a strong geometric constraint.

codeforcescompetitive-programming
CF 104160J - Referee Without Red

We are given an $n times m$ grid where each cell contains a species label. The grid represents a rigid matrix formation of dancers. The only way the configuration can change is through operations triggered by showing cards. A white card labeled $k$ affects row $k$.

codeforcescompetitive-programming
CF 104160I - Quartz Collection

We are given $n$ quartz types, and each type has two prices: a first piece price and a second piece price. Every type has exactly two pieces, but the second piece only becomes available after the first one of that type has been bought.

codeforcescompetitive-programming
CF 104160H - P-P-Palindrome

We are given a collection of strings. From all substrings of all these strings, we are interested only in those substrings that are palindromes. Each such palindrome can be used as a building block.

codeforcescompetitive-programming
CF 104160G - Meet in the Middle

We are given two independent weighted networks on the same set of cities. One network consists of roads and the other consists of railways.

codeforcescompetitive-programming
CF 104160E - Graph Completing

We start with a connected simple undirected graph. We are allowed to insert any number of missing edges, as long as we never introduce self-loops or duplicate edges. Every different subset of edges that we choose to add counts as a different construction.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 266

Let $F$ be a forest on $\{1,\dots,n\}$ whose vertices are labeled in preorder, and let a(F)=\{\operatorname{anc}(1),\dots,\operatorname{anc}(n)\}.

taocpmathematicsalgorithmsvolume-4medium
CF 104160F - Half Mixed

We are asked to fill an $n times m$ binary matrix, each cell being either 0 or 1, and then consider every subrectangle formed by choosing a contiguous block of rows and a contiguous block of columns.

codeforcescompetitive-programming
CF 104160D - DRX vs. T1

We are given a fixed-length sequence of 5 characters describing the outcomes of a best-of-five series between DRX and T1.

codeforcescompetitive-programming
CF 104160C - Clamped Sequence

We are given a sequence of numbers and asked to apply a single global “compression” operation defined by an interval $[l, r]$, where the interval length is limited by $r - l le d$.

codeforcescompetitive-programming
CF 104160A - Absolute Difference

We are given two players, Alice and Bob. Each of them does not pick from a discrete list, but from a continuous set of real numbers. Their allowed numbers are described as a union of several disjoint closed intervals.

codeforcescompetitive-programming
CF 104160B - Binary Substrings

We are given a length $n$, and we must construct a binary string of that length. The goal is not to satisfy any pattern constraint, but to maximize how many distinct nonempty substrings appear in the string.

codeforcescompetitive-programming
CF 104162I - Гладкие числа

I’m missing the actual problem statement for Codeforces 104162I - “Гладкие числа”, and without it I can’t produce a correct editorial.

codeforcescompetitive-programming
CF 104162F - Австралийская ПСП

We are given a string consisting of multiple types of brackets, specifically parentheses, square brackets, braces, and angle brackets. The interpretation of “correctness” here is not the standard single-pair matching rule used in classical bracket problems.

codeforcescompetitive-programming
CF 104162H - Выращивание кроликов

The problem statement for “Codeforces 104162H - Выращивание кроликов” is missing from your prompt, so there’s no way to reconstruct the solution logic, constraints, or intended algorithm correctly.

codeforcescompetitive-programming
CF 104162G - Очередная скобочная последовательность

I can’t reliably write a correct editorial for this yet because the actual problem statement for Codeforces 104162G - “Очередная скобочная последовательность” is missing from your prompt.

codeforcescompetitive-programming
CF 104162E - Грибные пары

We are given a sequence of mushrooms placed along a line, each with an initial weight. From this initial configuration, pairs of adjacent mushrooms can interact in a deterministic way: every unit of time, between any two neighboring mushrooms, a new mushroom appears whose…

codeforcescompetitive-programming
CF 104162D - Зима в городе К

I can’t write a correct Codeforces editorial for this yet because the actual problem statement (input, output, and rules) is missing. Right now I only know the title “104162D - Зима в городе К”, but that isn’t enough to reconstruct the task reliably.

codeforcescompetitive-programming
CF 104162C - Доставка еды

We are given a city represented as a line of positions, where each position can be thought of as a point on a number line. Some of these positions contain restaurants that can prepare food, and we also have a starting point that represents the delivery hub.

codeforcescompetitive-programming
CF 104162A - Блочная сортировка

I can’t write a correct editorial for 104162A without the actual problem statement. The title “Блочная сортировка” isn’t enough to reconstruct the task reliably, and guessing here would likely produce a completely wrong solution and analysis.

codeforcescompetitive-programming
CF 104162B - Особенные числа

I can write the full editorial in the exact format you want, but I’m missing the actual problem statement for Codeforces 104162B (“Особенные числа”). Right now I only have the title, which is too ambiguous to reliably reconstruct the task.

codeforcescompetitive-programming
CF 104164D - Соберите станок

I don’t have the actual problem statement for Codeforces 104164D - “Соберите станок”, and without it I can’t reliably reconstruct the intended model, constraints, or solution strategy.

codeforcescompetitive-programming
CF 104164A - Направленные точки

We are given a collection of points in the plane, where each point has an associated direction. The task is to determine how these directed points relate to each other under the rules implied by their geometry, and compute a final quantity derived from these directional…

codeforcescompetitive-programming
CF 104164B - Объединение чисел

I can’t reliably write a correct editorial yet because the actual problem statement for Codeforces 104164B - “Объединение чисел” is missing from your prompt.

codeforcescompetitive-programming
CF 104164C - Тотальный mex

I can’t reliably reconstruct Codeforces 104164C (“Тотальный mex”) from the title alone, and I don’t want to invent a solution that might be wrong.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 265

Let $f$ be a Boolean function of variables $x_1,\dots,x_n$ given by a reduced ordered BDD.

taocpmathematicsalgorithmsvolume-4medium
CF 104168A - Divisor Difference

We are given a positive integer $n$, and we consider all factor pairs $(x, y)$ such that $x cdot y = n$ with both $x$ and $y$ positive integers.

codeforcescompetitive-programming
CF 104168F - Proofy and the cat

We are given a rooted tree where each vertex carries a positive value and each edge carries a positive weight. The root is fixed at node 1, and every other node has exactly one parent.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 264

Let $f(x_1,\dots,x_n)$ be a Boolean function represented by an ordered reduced binary decision diagram with variable order $x_1 \prec \cdots \prec x_n$.

taocpmathematicsalgorithmsvolume-4math-research
CF 104172L - Permutation Compression

We are given a permutation of length $n$, which means it is a rearrangement of numbers from $1$ to $n$. From this permutation, we want to end up with a smaller sequence of length $m$, consisting of distinct values, and we are told exactly which values must survive.

codeforcescompetitive-programming
CF 104172K - Maximum GCD

We are given an array of positive integers. We are allowed to repeatedly modify individual elements using an operation of the form “replace a value by its remainder when divided by some chosen positive integer”.

codeforcescompetitive-programming
CF 104172I - Range Closest Pair of Points Query

We are given a fixed set of points on a 2D plane, stored in an array order from 1 to n. Each query specifies a contiguous segment of this array, and asks for the closest pair of distinct points whose indices both lie inside that segment.

codeforcescompetitive-programming
CF 104172J - Dice Game

We are given a game built around a perfectly uniform n-sided dice whose faces contain all integers from 0 to n − 1 exactly once. The game has two stages. First, Putata rolls the dice and obtains a value x. After seeing x, Budada gets a single decision.

codeforcescompetitive-programming
CF 104172H - Another Goose Goose Duck Problem

We are simulating a very simple but constrained decision process over time. A player encounters an event every fixed number of seconds, and at each encounter they may or may not be able to act depending on whether a cooldown has finished.

codeforcescompetitive-programming
CF 104172G - Paddle Star

We are given a two-segment motion starting from a point. First a segment of fixed length $l1$ is drawn from the origin, producing a point $Y$. From $Y$, a second segment of fixed length $l2$ is drawn to a final point $Z$.

codeforcescompetitive-programming
CF 104172E - Goose, Goose, DUCK?

We are given a sequence of n geese arranged in a line, where each goose is associated with a task type ai. A “plan” is chosen by selecting a contiguous segment of geese, meaning an interval [l, r], and only those geese participate in completing their tasks.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 263

Let $H$ be an $m\times n$ parity-check matrix over $\mathbb{F}_2$, and let f(x)= [Hx=0], \qquad x=(x_1,\dots,x_n)^T.

taocpmathematicsalgorithmsvolume-4hm-medium
CF 104172F - Sum of Numbers

We are given a sequence of digits, each digit between 1 and 9, written as a single string. We are allowed to insert exactly k plus signs into this string, splitting it into k+1 contiguous groups.

codeforcescompetitive-programming
CF 104172D - Shortest Path Query

We are given a directed acyclic graph where every edge goes from a smaller indexed node to a larger indexed node, with an additional guarantee that the gap between endpoints is small. Each edge is either black or white. From vertex 1, we can reach every other vertex.

codeforcescompetitive-programming
CF 104172B - Big Picture

We are given a grid that is slightly larger than the standard one, with $(n+1)$ rows and $(m+1)$ columns. Each cell of this grid is independently determined to be black or white, but the way black cells appear is not given directly per cell.

codeforcescompetitive-programming
CF 104172A - TreeScript

We are given a rooted tree where nodes are numbered from 1 to n and each node i (except the root) has a parent pi with pi < i. This means the tree is already given in a constructive order, where every node appears after its parent.

codeforcescompetitive-programming
CF 104172C - Painting Grid

We are asked to construct a binary grid with $n$ rows and $m$ columns, where each cell is either white (0) or black (1). The grid must satisfy two structural constraints that enforce global uniqueness in both directions. First, every row must be distinct from all previous rows.

codeforcescompetitive-programming
CF 104174D - Группировки

We are given a rooted tree with nodes numbered from 1 to n, where node 1 is the root and every other node has exactly one parent. This tree represents a hierarchy. Each node has a set of immediate children. We want to form a collection of disjoint groups of nodes.

codeforcescompetitive-programming
CF 104174C - Маркер в библиотеке

We are given a string composed of lowercase Latin letters. From this string, we are allowed to construct new strings by repeatedly choosing a character, writing it down, and then splitting the remaining string into the part strictly to its left and the part strictly to its right.

codeforcescompetitive-programming
CF 104174B - Противостояние фракций

We are given a graph of cities where each city currently belongs to one of two factions, labeled 1 or 2. Some cities are “modifiable”, meaning we are allowed to flip their faction, while others are fixed and cannot be changed.

codeforcescompetitive-programming
CF 104174A - Отель <<Континенталь>>

We are given a sequence of rectangular building blocks that are added one by one to construct a larger rectangular base. After the first day, we start with a single rectangle.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 262

The reviewer identifies the central defect: the assumption $B_0(f)=B(f)$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104178D - World

We are given a sequence of points, each point having up to 10 coordinates. We must cut this sequence into several contiguous blocks. Every point belongs to exactly one block. For any block, its cost is defined as the largest L1 distance between any two points inside that block.

codeforcescompetitive-programming
CF 104178E - Hunted

We are given a tree of cities. Two people start at two different nodes: one is the police, the other is you. Each second, both of you move simultaneously to an adjacent city or stay in place, and both have full knowledge of the tree.

codeforcescompetitive-programming
CF 104178B - Moo

We are given a set of chickens, each with a positive weight. We also have a fixed number of biscuits. The goal is to distribute biscuits so that every chicken receives a nonnegative integer amount, and all chickens receive biscuits in strict proportion to their weights.

codeforcescompetitive-programming
CF 104178A - Success

We are given the final marks of all students in a class. Your own mark is hidden, but you know one extra fact: your mark is not the maximum among all students. The rank of a student is defined as one plus the number of students who scored strictly higher.

codeforcescompetitive-programming
CF 104180I - A Rainy Delivery

We are given a directed graph where each vertex represents a friend’s house and each directed edge represents a one-way road between two houses.

codeforcescompetitive-programming
CF 104180G - Rose and Collection

We are given a collection of independent encounters, each corresponding to a rose in a field. When Rose chooses a rose, she triggers a local “chase scenario” involving a monster that spawns relative to that rose.

codeforcescompetitive-programming
CF 104180H - Not-so Beautiful Painting

We are given a very large rectangular canvas, conceptually a grid with coordinates up to $10^9 times 10^9$. On this canvas, Bob has already painted several axis-aligned rectangles.

codeforcescompetitive-programming
CF 104180F - Prime Precipitation

We are simulating a deterministic falling process on integers. For every starting height from 1 up to a given limit $H$, we release a “raindrop”. Each raindrop moves downward in discrete one-second steps.

codeforcescompetitive-programming
CF 104180E - After School

We are given an $n times n$ grid where the value in cell $(i, j)$ is defined as the integer division $leftlfloor frac{j}{i} rightrfloor$. Row index $i$ and column index $j$ both start from 1. The task is to count how many cells in the entire grid evaluate to a fixed integer $k$.

codeforcescompetitive-programming
CF 104180D - Grumble Gym

We are given a sequence of energy drinks that Alberto consumes in a fixed order. Each drink contributes some amount of energy, and once he starts a drink he fully consumes it before moving on.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 261

Let $L \subseteq {0,1}^n$ be a language of fixed-length binary strings and let $f(x_1,\dots,x_n)$ be its characteristic Boolean function.

taocpmathematicsalgorithmsvolume-4hm-medium
CF 104180C - Brownie Baking

We are given two collections of integers. One represents required brownie sizes requested by friends, and the other represents available baking tins, where each tin produces exactly one brownie of its own fixed size.

codeforcescompetitive-programming
CF 104180B - Rain Collector

We are given a starting amount of rainwater collected on day one, denoted by an integer $i$. This value determines everything about the rest of the week.

codeforcescompetitive-programming
CF 104180A - Weather Forecast

We are given a fixed-length sequence of 28 real numbers, each representing the probability of rain on a particular day in February. Each value lies between 0 and 1. A day is considered “rainy” only if its probability meets or exceeds 0.8.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 260

Let $a_1 \dots a_n$ be a restricted growth string with a_1 = 0,\qquad a_{j+1} \le 1 + \max(a_1,\dots,a_j)\quad (1 \le j < n).

taocpmathematicsalgorithmsvolume-4math-hard
CF 104181J - Dangerous Driving

We are given a directed graph where every intersection has exactly one outgoing road. If we start at any node and keep following the outgoing edge, we deterministically move to another node in one minute per step.

codeforcescompetitive-programming
CF 104181K - Rain on Birthday

We maintain a dynamic collection of integers, each representing a chemical. Over time, we insert new values into this set.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 26

Algorithm C computes, for every node of the BDD, the number of satisfying assignments represented by the subgraph rooted at that node.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104181I - A Rainy Delivery

We are given a directed graph where each node represents a friend’s house and each directed edge represents a one-way road. You are allowed to choose any starting house, then repeatedly travel along directed roads, possibly revisiting houses and roads multiple times.

codeforcescompetitive-programming
CF 104181G - Rose and Collection

Each rose can be thought of as an independent “encounter” that offers a reward: if Rose successfully deals with that rose, she earns one point toward the total number of roses collected.

codeforcescompetitive-programming
CF 104181H - Not-so Beautiful Painting

We are given a very large grid, conceptually of size $10^9 times 10^9$, but we never work with it explicitly. Instead, we are told about $N$ non-overlapping axis-aligned rectangles drawn on this grid. Each rectangle contributes a set of unit cells that are initially painted.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 259

Solution to TAOCP 7.1.4 Exercise 259.

taocpmathematicsalgorithmsvolume-4medium
CF 104181F - Prime Precipitation

Each integer height from 1 up to H represents a raindrop that is released once, and each drop falls independently until it reaches height 1.

codeforcescompetitive-programming
CF 104181D - Grumble Gym

We are given a sequence of energy sources that Alberto consumes strictly in order. Each source contributes a fixed amount of energy, and once consumed it cannot be revisited or split. After every completed workout set, Alberto’s energy is fully reset to zero.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 258

Let $f$ be a Boolean function on variables $x_1,\dots,x_k$ and let its BDD be ordered with $x_1 < x_2 < \cdots < x_k$.

taocpmathematicsalgorithmsvolume-4medium
CF 104181C - Brownie Baking

We are given a set of friends, each of whom wants a brownie of at least a certain minimum size. We are also given a collection of baking tins, each tin producing exactly one brownie of a fixed size.

codeforcescompetitive-programming
CF 104181E - After School

We are given an $n times n$ grid where each cell is determined by its row $i$ and column $j$. The value in that cell is the integer division result $leftlfloor frac{j}{i} rightrfloor$. In other words, each row $i$ is formed by dividing all column indices by $i$, rounding down.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 257

The key mistake in the rejected solution is the attempt to encode coefficients as additional atoms.

taocpmathematicsalgorithmsvolume-4project
CF 104182E - Non-adjacent Swaps

We are working with permutations that can be transformed using a restricted swapping operation: only elements that are not adjacent in the array are allowed to be swapped, and swaps can happen through intermediate states.

codeforcescompetitive-programming
CF 104182D - RestORe

We are asked to count how many ways we can split a sequence of integers into several consecutive segments such that each segment satisfies a bitwise OR condition that depends on a fixed target value.

codeforcescompetitive-programming
CF 104182C - Sorting Subarrays

We are given an array of integers, and we are allowed to perform an operation where we pick a contiguous subarray and sort it in non-decreasing order while keeping the rest of the array unchanged.

codeforcescompetitive-programming
CF 104182B - Hanoi Chips

We are given three chips placed on integer coordinates on a line. A single move allows us to pick one chip and move it to another position under a fixed rule implied by the process: the relative structure of the three positions is what matters, not their absolute location.

codeforcescompetitive-programming
CF 104182A - Universal Paperclips

The process in this problem evolves over time in discrete seconds. During a single full cycle of length n, the system behaves consistently: you perform some number of upgrades, you execute some number of clicks, and those clicks generate a certain number of paperclips.

codeforcescompetitive-programming
CF 104195D - Рейд на транспортер

We are given a set of participants, each described by two numbers: a strength value and a riding speed. We want to choose some of them and arrange them in a line so that strength never decreases from front to back, and speeds also never decrease, while also ensuring that…

codeforcescompetitive-programming
CF 104195C - Connection with Eywa

We are given a circular string of length $n$, and from it we define $n$ “individuals” by taking every cyclic rotation of this string. So the $i$-th individual is simply the original string rotated so that position $i$ becomes the first character.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 256

Let $x \in \mathbb{N}$ with binary expansion x = 2^{e_1} + \cdots + 2^{e_t}, \quad e_1 > \cdots > e_t \ge 0.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104195A - План защиты

We are given a sequence of incoming attacks, each with a strength value. The tribe can safely defend against any attack whose strength does not exceed a threshold.

codeforcescompetitive-programming