brain

tamnd's digital brain — notes, problems, research

43815 notes

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 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 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 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
CF 104195B - Паякан в беде

I can’t write a correct editorial without the actual problem statement. “Codeforces 104195B - Паякан в беде” isn’t enough on its own, and I don’t have the task details (input format, constraints, or what needs to be computed).

codeforcescompetitive-programming
CF 104196M - Tomb Hater

We are given a rectangular grid of characters, and a list of valid words over the same alphabet. A path starts on any cell in the top row and must end on any cell in the bottom row. Each move goes one step to the South, West, or East, and stepping outside the grid is forbidden.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 255

A multifamily $f$ assigns to each set $\alpha$ a multiplicity $m_f(\alpha) \in \mathbb{N}$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.4 Exercise 254

Let the Shannon decompositions from (52) be written in the standard form for monotone functions, f = (\bar x_1 \wedge f_l)\ \vee\ (x_1 \wedge f_h), \qquad g = (\bar x_1 \wedge g_l)\ \vee\ (x_1 \wedge...

taocpmathematicsalgorithmsvolume-4math-medium
CF 104196L - Statues

We are given a small grid representing a park. Each cell is either empty water, marked by −1, or contains a statue with a unique positive height. All statues are distinct, so we can think of them as having a strict global order from smallest to largest.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 253

Let $f(x_1,\ldots,x_n) = (\bar{x}_1 \wedge f_0) \vee (x_1 \wedge f_1)$, where $f_0, f_1$ are Boolean functions of $x_2,\ldots,x_n$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104196K - Stable Table

We are given a rectangular grid made of unit squares, where each cell belongs to exactly one labeled piece. A single piece is a connected set of cells (connected by shared edges), and different pieces can be interwoven, even containing holes formed by other pieces.

codeforcescompetitive-programming
CF 104196I - Pinned Files

We are given a list of files, each file having a unique label from 1 to n. At any moment, the editor maintains an ordering of these files, but this ordering is split into two contiguous parts.

codeforcescompetitive-programming
CF 104196F - Growing Some Oobleck

We are given a set of circles in the plane. Each circle starts with a fixed center, an initial radius, and a linear growth speed. As time increases, every circle expands outward, so its radius increases linearly.

codeforcescompetitive-programming
CF 104196D - Downsizing

We are given a circle centered at a fixed point $O$ with radius $r$, and a convex polygon that lies entirely outside the interior of this circle.

codeforcescompetitive-programming
CF 104196E - Gambling Game

We are given a random ordering of the numbers from 1 to m. Think of it as shuffling m distinct tokens and revealing them one by one. Alongside this, we are given a “card” made of n disjoint pairs of numbers.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 252

Let $f(x_1,\dots,x_n)$ be a monotone Boolean function.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104196A - 1s For All

The task defines a way to “build” an integer using only the digit one, combined with three operations: addition, multiplication, and digit concatenation.

codeforcescompetitive-programming
CF 104196C - Ball of Whacks

The object in this problem is a fixed 30-piece polyhedron where each piece has a well-defined position in a global structure.

codeforcescompetitive-programming
CF 104196B - Abridged Reading

We are given a collection of chapters where each chapter has a page cost. There are directed dependency relations of the form “chapter a must be read before chapter b”, and each chapter can depend on at most one earlier chapter.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 251

Let $f(x_1,\dots,x_n)$ be a monotone Boolean function.

taocpmathematicsalgorithmsvolume-4math-research
CF 104197K - King of Swapping

We are given a directed graph on $n$ vertices. Each vertex represents a position containing a number, and the graph encodes allowed moves of a distinguished element (the “king”) or, equivalently, allowed swaps between positions. A move is only possible along directed edges.

codeforcescompetitive-programming
CF 104197L - Least Annoying Constructive Problem

We are given an odd number of vertices or an even number with a small adjustment, and we must explicitly construct a structured list of edges between labeled nodes.

codeforcescompetitive-programming
CF 104197I - Increasing Grid

We are given an $n times m$ grid where some cells are already fixed to be either 0 or 1. Our task is to count how many full completions of the grid exist such that the final matrix is non-decreasing along both rows and columns, and all pre-filled constraints are satisfied.

codeforcescompetitive-programming
CF 104197H - Help Me to Get This Published

We are working with a complete graph whose edges are colored, with the restriction that no triangle uses three distinct colors. This restriction is the classical Gallai property and it forces a strong hierarchical structure on how colors can appear across the graph.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 250

A monotone Boolean function $f(x_1,\dots,x_5)$ is uniquely represented by its set of minimal true points, an antichain $A \subseteq 2^{[5]}$, and conversely every antichain determines such a function...

taocpmathematicsalgorithmsvolume-4hard
CF 104197G - Graph Problem With Small $n$

We are given a graph with vertices numbered from 0 to n − 1, where n is small enough that we can consider subsets of vertices explicitly. The graph is undirected, and the core task revolves around reasoning about Hamiltonian paths that are constrained to subsets of vertices.

codeforcescompetitive-programming
CF 104197F - F*** 3-Colorable Graphs

We are given a connected undirected graph. The vertices are already conceptually split into two groups by index, but that split is only used as a starting coloring trick: vertices in the first group can be colored differently from the second group so that the original graph is…

codeforcescompetitive-programming
CF 104197D - Distance Parities

We are given a complete description of pairwise distances between nodes in a hypothetical graph, but only the parity of those distances matters.

codeforcescompetitive-programming
CF 104197E - Excellent XOR Problem

We are given an array of integers, and the task is to decide whether it can be split into multiple contiguous parts under constraints defined by XOR values of these parts.

codeforcescompetitive-programming
CF 104197B - Binary Arrays and Sliding Sums

We are working with binary arrays of length $n$, where each element is either 0 or 1. From any such array $a$, a derived array $b$ is defined through sliding sums over a fixed window size $k$.

codeforcescompetitive-programming
CF 104197A - Adjacent Product Sum

We are given a list of numbers and we want to place them around a circle. Once placed, every element contributes to the total score through the product with its two neighbors on the circle.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 25

Algorithm C in this section evaluates a BDD bottom-up by assigning to each node $v$ a value depending only on its LO and HI successors, with sink nodes providing the base cases and each internal node...

taocpmathematicsalgorithmsvolume-4math-medium
CF 104199J - Кошачий ужин

We are given a line of cats, each with a fixed “happiness contribution” if it eats from its personal bowl. There is also one shared bowl that any number of cats can use. If a cat uses its own bowl, it contributes its value, otherwise it contributes nothing.

codeforcescompetitive-programming
CF 104199D - Демонтаж

We are given a row of buildings, each with a fixed height. You start from the ground outside the buildings, and your goal is to retrieve an item located on the roof of a specific building indexed by m.

codeforcescompetitive-programming
CF 104199B - Расстановка мебели

We are given a hotel with several rooms, each room having a required number of chairs in an ideal plan. In reality, the hotel has a total of $N$ chairs that must be distributed across $K$ rooms.

codeforcescompetitive-programming
CF 104199C - Безлюдный отель

We are given a word written as a sequence of lowercase Latin letters. A token starts on the first character and moves according to a deterministic rule that depends entirely on how many times the current character appears in the word.

codeforcescompetitive-programming
CF 104199A - Лифт

We start at floor 0 and want to reach a target floor D. At every move, the elevator allows exactly two possible actions: go up by 3 floors or go down by 2 floors. Each action counts as one button press.

codeforcescompetitive-programming