brain

tamnd's digital brain — notes, problems, research

41641 notes

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 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
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
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
TAOCP 7.1.4 Exercise 249

Let $f(x_1,\dots,x_n)$ be a Boolean function with truth table $\tau$ and BDD $T(f)$.

taocpmathematicsalgorithmsvolume-4hm-hard
CF 104207K - Knightmare

We are watching a knight moving on an infinite chessboard. It starts from a single square, and every time it jumps, it moves according to the usual chess knight rules.

codeforcescompetitive-programming
CF 104207I - Inkopolis

We are given a connected undirected graph with exactly one cycle, meaning the number of edges equals the number of vertices. Each edge has a color.

codeforcescompetitive-programming
CF 104207H - Equidistance

We are given several points in an N-dimensional Euclidean space. The key condition is that every pair of given points is exactly one unit apart, so these points already form a perfectly regular geometric structure where all mutual distances are identical.

codeforcescompetitive-programming
CF 104207J - Subway Chasing

We are given a linear subway line with stations numbered from 1 to N. Between every pair of adjacent stations i and i+1 there is an unknown travel time ti, and these values are strictly positive integers bounded above by 2×10^9.

codeforcescompetitive-programming
CF 104207F - Fair Lottery

We are given several groups of people. Each group has a fixed size, and if a group is chosen in a lottery outcome then all its members win together. In any single outcome, the total number of winners across all chosen groups is limited by an upper bound $M$.

codeforcescompetitive-programming
CF 104207G - Alice's Stamps

We are given a line of positions from 1 to N, where each position represents a distinct stamp type. Instead of buying stamps individually, Alice can only purchase bundles, and each bundle contributes all stamp types in a contiguous interval [L, R].

codeforcescompetitive-programming
CF 104207B - Same Digit

We are given a single digit $D$ and a target integer $N$. Using only copies of the digit $D$, we are allowed to build arithmetic expressions using concatenation and standard operations like addition, subtraction, multiplication, division, factorial, negation, and a few unary…

codeforcescompetitive-programming
CF 104207D - Mr. Panda and Circles

We are working on a line segment that has integer positions from 0 to $M-1$. At each integer coordinate we may place at most one circle center, and we must place all $N$ circles.

codeforcescompetitive-programming
CF 104207E - Evil Forest

We are asked to size production for a sequence of painting competitions. Each competition has a known number of participants, and every participant consumes exactly one sketchpad.

codeforcescompetitive-programming
CF 104207C - Rich Game

Each test case describes a repeated interaction where a player tries to maximize how many badminton sets he can win, starting with no money. In each point of a match, he can choose whether to intentionally win or lose that point.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 248

A Boolean function is sweet when every subtable arising from any prefix assignment is a bead.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104207A - Dogs and Cages

We are given a system with the same number of dogs and cages, both labeled from 0 to N − 1. Each dog independently chooses a cage uniformly at random, and each cage can hold at most one dog, which means the final configuration is a random permutation of the dogs over the cages.

codeforcescompetitive-programming
CF 104217H - Sled Ordering

We are building ordered sequences of length $N$, where each position is filled with one of two indistinguishable types: spotted or brown. Because cows of the same type are identical, a valid configuration is fully described by a binary string of length $N$.

codeforcescompetitive-programming
CF 104217F - The Austin Longhorn Race

We are given a set of checkpoints scattered in a 2D plane. Each checkpoint appears only at a specific time, and if we happen to be exactly at its coordinates at that exact time, we can collect some amount of reward.

codeforcescompetitive-programming
CF 104217G - Journey to Nome

Let the given BDD for $f(x1,dots,xn)$ be a rooted directed acyclic graph whose branch nodes are labeled by variables $V(u)in{1,dots,n}$ and whose sink nodes are $bot,top$, with orderedness ensuring that along every directed path the labels strictly increase.

codeforcescompetitive-programming
CF 104217E - Snowy Hill

We are given an array representing snow heights along a straight hill. The array is monotonic non-decreasing, meaning as we move from index 0 to index N−1, values never decrease.

codeforcescompetitive-programming
CF 104217D - Outfit Ordeal

Connection interrupted. Waiting for the complete answer

codeforcescompetitive-programming
CF 104217C - Sled Circle

We are dealing with a circular track of n evenly spaced positions, labeled from 0 to n-1. Each dog starts at a unique position i, and every dog moves clockwise at a constant speed vi, meaning that after t time steps, dog i will be located at position (i + t · vi) mod n.

codeforcescompetitive-programming
CF 104217A - Swapped Signs

We are given two uppercase strings, one representing the current word displayed on a board and another representing the word we want to replace it with.

codeforcescompetitive-programming
CF 104217B - Max Difference

We are given a single integer $n$, and we are asked to look at all permutations of the sequence $(1, 2, 3, dots, n)$. Each permutation is interpreted as a number formed by concatenating its elements in order.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 247

A truth table of order $n$ is a binary string of length $2^n$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104218J - March March

We are given a directed graph on $n le 20$ labeled cities, where some one-way roads already exist. The intended goal is to ensure that there is a valid “March March route” that visits cities in order from 1 through $n$, meaning that for every consecutive pair $i to i+1$, we…

codeforcescompetitive-programming
CF 104218I - Balto's Training

We are given a directed structure over $N$ villages. From every village there are exactly two outgoing roads: one labeled left and one labeled right, each pointing to some (possibly the same or different) village.

codeforcescompetitive-programming
CF 104218G - Journey to Nome

We are given a fixed number $M$, and we are interested only in positive integers that share no prime factor with $M$. In other words, we filter the natural numbers and keep only those that are coprime to $M$, then index this filtered sequence starting from 1.

codeforcescompetitive-programming
CF 104218E - Snowy Hill

We are given an array representing snow heights along a straight hill. The values are non-negative and the sequence is monotonic non-decreasing from left to right. Each query asks for a contiguous segment whose elements sum exactly to a given value $K$.

codeforcescompetitive-programming
CF 104218D - Outfit Ordeal

We are simulating a stack-like wardrobe where clothing items are inserted, removed from the top, and occasionally removed from the middle by name. Each operation modifies or queries this pile. There are three operations.

codeforcescompetitive-programming
CF 104221B - Динислам и столовая

We are given a line of students who must eventually “clear” their dishes, and each student contributes some amount of work measured in seconds. The initial situation contains a queue of $n$ existing students.

codeforcescompetitive-programming
CF 104221E - Чайный магазин

We are given several possible positions for a shop along a straight line and a set of customers, each living at a fixed point and having a personal tolerance threshold.

codeforcescompetitive-programming
CF 104221D - Карим и дороги

We are given an undirected simple graph with $n$ intersections and $m$ roads. Each road connects two distinct intersections, and between any pair of intersections there is at most one road.

codeforcescompetitive-programming
CF 104221C - Кузя и день рождения

Kuzya is preparing a birthday party, but the number of guests he can invite depends entirely on how a cake is sliced at an unknown bakery. There are several bakeries in his city, and each bakery always cuts a cake into a fixed number of slices.

codeforcescompetitive-programming
CF 104221A - Сафия и подсчет карандашей

Something went wrong. If this issue persists please contact us through our help center at help.openai.com.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 246

Let $G=(V,E)$ be a graph, and let $f$ be a monotone Boolean function on $V$ expressed in family algebra as in Section 7.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104229D - Tourists

We are given a country whose road network forms a tree. Each city is a node, and every pair of cities is connected by exactly one simple path.

codeforcescompetitive-programming
CF 104229B - Lego Wall

We are building a rectangular structure of width $w$ and height $h$ using two types of pieces. One piece is a single unit cube that occupies exactly one cell. The other is a domino-shaped piece of size $2 times 1$, placed horizontally, covering two adjacent cells in the same row.

codeforcescompetitive-programming
CF 104229C - SocialEngineering

We are given a connected undirected graph where vertices represent people and edges represent friendships. Two players take turns moving along edges, effectively walking through the graph, but with a strict rule that each edge can be used at most once throughout the entire play.

codeforcescompetitive-programming
CF 104230D - Chika Wants to Cheat

We are designing a system that assigns a unique identifier to each number using a pattern drawn on a very small geometric canvas, a 2 by 2 square with integer lattice points.

codeforcescompetitive-programming
CF 104230B - Superpiece

We are working on an infinite chessboard where each query gives a start square and a target square, together with a set of chess pieces that are allowed to be used. A move means choosing one of the allowed pieces and applying one legal move of that piece from the current square.

codeforcescompetitive-programming
CF 104234M - Siteswap

We are given a sequence that describes a repeating juggling pattern over discrete beats. On each beat, either a throw happens with a specified delay, or nothing happens.

codeforcescompetitive-programming
CF 104234L - Directed Vertex Cacti

We are asked to count how many directed graphs can be formed on n labeled vertices under two structural restrictions, together with a global edge count constraint.

codeforcescompetitive-programming
CF 104234K - Determinant, or...?

We are given an array of length $2^n$, and from it we construct a $2^n times 2^n$ matrix. The rows and columns are indexed from $0$ to $2^n - 1$, and the entry at position $(i, j)$ is defined as $a{i , So each matrix entry does not depend on two independent values of the array…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 245

Let $f:\{0,1\}^n\to\{0,1\}$ be monotone.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104234J - Persian Casino

We are simulating a constrained gambling process that behaves less like independent betting and more like a controlled state machine with limited “time travel” resets. Prince starts with a single coin and must go through exactly n betting rounds.

codeforcescompetitive-programming
CF 104234I - DAG Generation

We are looking at a randomized procedure that constructs a directed acyclic graph by processing vertices one by one. At any moment there is a set of already inserted vertices, and a set of remaining vertices.

codeforcescompetitive-programming
CF 104234G - Palindromic Differences

We are given an array of numbers, and we are allowed to reorder it arbitrarily. For each chosen ordering, we build a second array consisting of consecutive differences between adjacent elements.

codeforcescompetitive-programming
CF 104234H - Graph Isomorphism

We are given an undirected simple graph on $n$ vertices. From this graph, we conceptually generate all graphs that can be obtained by relabeling vertices in every possible way. Two relabelings that produce different edge sets count as different graphs.

codeforcescompetitive-programming
CF 104234F - Palindromic Polynomial

We are given several independent test cases. In each one, a hidden polynomial is known to have a symmetric coefficient pattern, meaning the coefficient list reads the same from left to right and from right to left.

codeforcescompetitive-programming
CF 104234E - Garbage Disposal

We are given a continuous block of integers from L to R. Think of these numbers as both “positions” and “items” at the same time. For every number i in this segment, we must assign it a distinct number yᵢ from the same segment, forming a permutation of the interval.

codeforcescompetitive-programming
CF 104234D - Triterminant

We are given a binary sequence where each element is either +1 or −1. From this sequence we build, for every prefix length k, a determinant of a special k by k matrix.

codeforcescompetitive-programming
CF 104234B - Super Meat Bros

We are building two independent story sequences, one for Meatio and one for Meatigi. Each sequence is formed by concatenating story arcs.

codeforcescompetitive-programming
CF 104234C - Testing Subjects Usually Die

We are repeatedly trying to identify a hidden number between 1 and n. The hidden number is not chosen uniformly: each value i has a given weight pi, and the actual probability of being the correct answer is proportional to these weights.

codeforcescompetitive-programming
CF 104234A - Square Sum

We are given a modulus $m$, and then a list of values $z1, z2, dots, zn$. For each query value $zi$, we want to count how many ordered pairs $(x, y)$ with $0 le x, y < m$ satisfy the congruence $$x^2 + y^2 equiv zi pmod m.

codeforcescompetitive-programming
CF 104235J - Счастливая конфигурация

We are given an array length $n$ and a prime number $k$ such that $n$ is divisible by $k$. The indices $1..n$ form a permutation $P$, and we are asked to construct such a permutation. The constraint introduces a second hidden object: another permutation $B$ of $1..

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 244

Let the edges of $P_3$ be $e_1$ and $e_2$, where $e_1$ joins vertices $1$ and $2$, and $e_2$ joins vertices $2$ and $3$.

taocpmathematicsalgorithmsvolume-4medium
CF 104235I - Отгадай два числа

We are interacting with a hidden pair of integers $A$ and $B$, both in the range from $0$ to $10^9$. We do not see them directly. Instead, we can send a query value $X$, and the system returns the value $(A oplus X) + B$, where $oplus$ is bitwise XOR.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 243

Let $\mathcal{f}$ be a family of sets.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104235H - Красно-синие маршруты

We are given a directed graph where every vertex has exactly two outgoing edges: one red edge and one blue edge. From any starting vertex, a move consists of repeating a fixed pattern of edge traversals, and we must determine where we end up after applying that pattern many…

codeforcescompetitive-programming
CF 104235E - Запросы на массиве

We are maintaining a mutable array where two operations repeat over time. One operation asks, for a fixed position i, to look strictly to the right and find the smallest value that is strictly greater than a[i]. The other operation flips the sign of a single element in the array.

codeforcescompetitive-programming
CF 104235D - На уголки не разрезать!

We are given a rectangular grid of size $n times m$, fully covered by unit cells. A player wants to tile all remaining cells after removing exactly one cell using a specific shape called a “corner tromino”: a shape made of three cells that forms an L, i.e.

codeforcescompetitive-programming
CF 104235C - Разговор о деревьях

We are working with a tree on $n$ vertices where vertex 1 and vertex 2 are fixed in a special way: the distance between them is exactly $m$, and no pair of vertices in the tree is farther apart than $m$.

codeforcescompetitive-programming
CF 104235B - Мед в сотах

We are given two identical geometric objects on a grid, each object is a regular hexagon of side length 1. Each hexagon is placed in a fixed orientation: two of its edges are vertical, and its lowest vertex is anchored at an integer coordinate point.

codeforcescompetitive-programming
CF 104235A - Красивое окно

We are given a rectangular window of height H and width W. Two cuts are made. First, we choose a vertical cut at some integer position A, splitting the window into a left rectangle of width A and a right rectangle of width W - A.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 242

A set $S \subseteq {1,\dots,8}^2$ is admissible if no three distinct points of $S$ lie on a common affine line in $\mathbb{R}^2$.

taocpmathematicsalgorithmsvolume-4medium
CF 104236J - Discount Spiderman

We are given a set of vertical “trees” placed at distinct x-coordinates. Each tree is just a segment from ground level up to some height. Alice starts at the leftmost side and moves strictly from left to right, but she does not move along the ground.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 241

Let $Q_8$ be the queen graph on the $8\times 8$ chessboard.

taocpmathematicsalgorithmsvolume-4hard
CF 104236H - Environmental Policy

We are given an array of integers representing environmental impact scores for different policies. Each query asks us to look inside a fixed segment of this array and consider only subarrays whose lengths lie inside a given range.

codeforcescompetitive-programming
CF 104236I - Possible Meetings

We are given a sequence of animals arranged in a line. Each animal has two attributes: a species label and a skill value. The task is to consider every contiguous segment of this line and compute a score for each segment.

codeforcescompetitive-programming
CF 104236G - Aranara Game (Hard)

We are given a directed graph on $N$ nodes where every node has exactly one outgoing edge. From each node $i$, there is a deterministic move to $nxti$. Two tokens start on nodes $a$ and $b$. In every round, both tokens simultaneously follow their outgoing edges.

codeforcescompetitive-programming
CF 104236F - Meltdown

We are given a row of $N$ ice pillars, each with an initial integer height. Over time, the system receives two kinds of operations applied to subarrays.

codeforcescompetitive-programming
CF 104236D - J IDs

We are given a rectangular grid, and two players are placed on two different cells. The grid has no obstacles, so movement is always possible in the four cardinal directions.

codeforcescompetitive-programming
CF 104236E - Wifi Connection

We are given a set of points on a 2D plane, each representing an observation station in a national park. Every station is equipped with a wireless device that has a uniform power level $P$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 240

Let $G=(V,E)$ be a finite graph.

taocpmathematicsalgorithmsvolume-4medium
CF 104236C - Testing Building Strength

We are given a chain of rigid segments placed end to end in the plane. Each segment has a fixed length, and consecutive segments are connected by joints that allow rotation.

codeforcescompetitive-programming
CF 104236A - Aranara Game (Easy)

We are given a directed structure on $N$ nodes where each node has exactly one outgoing edge to another node, and no node points to itself.

codeforcescompetitive-programming
CF 104236B - Perfect Parks

We are given an ordering of the numbers from 1 to N placed across N positions. Think of the array a as Larry’s “ideal layout”, where position i ideally wants the value a[i]. Harry is allowed to rearrange the same set of values 1 through N into another permutation b.

codeforcescompetitive-programming
CF 104237J - Colossal Cash

We are given a set of barns arranged as vertices in a graph. Each barn gives Joe a fixed profit every time he arrives there. Between barns there are directed roads, each with an associated cost.

codeforcescompetitive-programming
CF 104237I - Mostly Successful Mailman

We are asked to count how many permutations of the numbers from 1 to N the farmer can produce while making at most K “mistakes”. A mistake occurs at a position i if the value placed at position i is not i itself.

codeforcescompetitive-programming
CF 104237H - Sunset Drifting

We are given a grid representing a city map where each cell is either free road, an obstacle, a start position, or one or more exits.

codeforcescompetitive-programming