brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 103688D - Collision Detector

We are given three fixed points in the plane, each representing the center of a unit circle (radius is 1 for every ball). One ball starts at $O1$ and we are allowed to choose its initial velocity vector arbitrarily.

codeforcescompetitive-programming
CF 103688B - Lovely Fish

We are given a binary string. Each character describes whether a coworker likes Fish or not. For any query, we take a contiguous substring and are allowed to insert any number of 1s at arbitrary positions.

codeforcescompetitive-programming
CF 103688A - Bookshelf Filling

We are given two types of books that behave identically in width when placed upright: every book occupies exactly one unit of shelf width. The difference is in height. Type A books have height a, and type B books are taller with height b, where a < b.

codeforcescompetitive-programming
CF 103688C - Tree Division

We are given a tree with n nodes, and each node carries an integer value. We fix node 1 as a special root candidate, and we need to decide whether it is possible to partition all nodes into two disjoint groups A and B such that a monotonic constraint holds along every simple…

codeforcescompetitive-programming
CF 104237F - Perfect Parks

We are given a target arrangement of tree heights, where the heights are exactly the integers from 1 to N with no repetition. The array a describes how Larry wants the trees to appear along a line, position by position.

codeforcescompetitive-programming
CF 104237C - Trash Removal

We are given a sequence of trash piles arranged in a fixed order along a path. Each pile has a weight, and Bob must pick up piles from left to right without skipping or reordering them.

codeforcescompetitive-programming
CF 104229A - SubsetMex

We are given a multiset of non-negative integers, but instead of listing all elements explicitly, the input gives frequencies up to some value range. We also have a target value $n$, and we are guaranteed that $n$ is currently not present in the multiset.

codeforcescompetitive-programming
TAOCP 7.2.1.2 Exercise 3

Let $n = s + t$ and let $ct , ct-1 \dots c1$ be a $t$-combination of ${0,1,\dots,n-1}$ written in decreasing order, and let $bs \dots b1$ be the dual representation listing the positions of the zeros...

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.2 Exercise 2

Let $n = s + t$ and let $ct , ct-1 \dots c1$ be a $t$-combination of ${0,1,\dots,n-1}$ written in decreasing order, and let $bs \dots b1$ be the dual representation listing the positions of the zeros...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.2 Exercise 1

Algorithm L spends its time determining, at each step, the two array positions $ a_{j-c_j+s} $ and $ a_{j-q+s} $ that must be interchanged, where $q = c_j + o_j$ and where the auxiliary variable $s$ c...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 99

Let $N = 2^n$ and let $f_n(0), f_n(1), \ldots, f_n(N-1)$ be the cycle from Exercise 97, viewed cyclically modulo $N$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 98

The central issue is that the previous solution never derived a usable recurrence for the prefix sum S_n(k)=\sum_{j=0}^{k-1} f_n(j), and instead _assumed_ it inherits the same recursive structure as $...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 97

We restart from the actual structure of Algorithms R and D in TAOCP §7.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 96

We consider the recursive coroutine framework described in Section 7.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 95

Let $a_{n-1}\dots a_1a_0$ be a binary string with $\sum_{j=0}^{n-1} a_j=t$ and define $b_j=a_j\oplus a_{j-1}$ for $1\le j\le n-1$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 94

For $m=5$ and $n=1$, the objects being cycled are single symbols from the alphabet ${0,1,2,3,4}$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 93

We repair the proof by eliminating the false DFS assumptions and instead proving correctness directly from the recursive _edge-consumption structure_ of Algorithm R.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 92

Fix $n \ge 1$.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 91

Let $[n]={1,2,\dots,n}$ and let $\mathcal A$ be a family of $r$-subsets of $[n]$ such that for all $\alpha,\beta\in\mathcal A$ one has $\alpha\cap\beta\neq\varnothing$, with $r\le n/2$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 90

Let $[n]={1,2,\dots,n}$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 89

Let $M(n)$ be the set of words over $\{\cdot,-\}$ with total weight $n$, where $\cdot$ has weight $1$ and $-$ has weight $2$.

taocpmathematicsalgorithmsvolume-4medium
CF 104235G - Хорошие таблицы

We are given a grid of size $n times m$ filled with lowercase Latin letters. From this grid, we consider all possible axis-aligned subrectangles.

codeforcescompetitive-programming
CF 104235F - Вероятность хорошей последовательности

We generate a random array of length $n$, where each position is independently and uniformly chosen from integers $1$ to $k$. Every one of the $k^n$ arrays is equally likely.

codeforcescompetitive-programming
CF 104230C - Toy Design

We are given a hidden undirected graph on $n$ labeled nodes. The structure of this graph is called design 0, but we are never shown its edges directly.

codeforcescompetitive-programming
CF 104230A - Data Centers

We are given a collection of data centers, each starting with some number of available machines. A sequence of services arrives one by one, and each service consumes machines in a very specific way: it looks at the current state of all data centers, sorts them by how many…

codeforcescompetitive-programming
CF 104218H - Sled Ordering

Codeforces 104218H: Sled Ordering

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 88

We analyze Algorithm K as a generator of a cyclic Gray code on the $n$-cube, as constructed in Knuth’s treatment.

taocpmathematicsalgorithmsvolume-4medium
CF 104218F - The Austin Longhorn Race

We are given a set of events, each located at a point on a 2D plane and occurring at a specific time. Each event also has a value.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 87

The failure in the proposed solution is indeed not about coverage or monotone radius, but about an unjustified structural claim: one cannot appeal to a “standard Hamiltonian cycle on the shell” withou...

taocpmathematicsalgorithmsvolume-4hard
CF 103964B - Build Towers

We are given a collection of vertical sticks, each stick holding a stack of plates. Each plate has a color and a size, and for every color there are exactly seven plates with sizes from 0 to 6.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 86

A Gray code on the set of all $n$-tuples $(a_1,\dots,a_n)$ of nonnegative integers is an infinite sequence in which every tuple appears exactly once and successive tuples differ in exactly one compone...

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 85

Represent each domino ${i,j}$, $0 \le i \le j \le 6$, as an undirected edge between vertices $i$ and $j$ in a multigraph $G$ on vertex set ${0,1,\dots,6}$, with one loop at each vertex $i$ correspondi...

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 84

Represent each domino ${i,j}$, $0 \le i \le j \le 6$, as an undirected edge between vertices $i$ and $j$ in a multigraph $G$ on vertex set ${0,1,\dots,6}$, with one loop at each vertex $i$ correspondi...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 83

Represent each domino ${i,j}$, $0 \le i \le j \le 6$, as an undirected edge between vertices $i$ and $j$ in a multigraph $G$ on vertex set ${0,1,\dots,6}$, with one loop at each vertex $i$ correspondi...

taocpmathematicsalgorithmsvolume-4project
TAOCP 7.2.1.1 Exercise 82

The error in the proposed solution is fundamental: it tries to generate Hamilton cycles by modifying a single coordinate while keeping all others fixed.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 81

Let $C$ denote the 2-digit $m$-ary modular Gray code cycle (a_0,b_0)\to(a_1,b_1)\to\cdots\to(a_{m^2-1},b_{m^2-1})\to(a_0,b_0), and let $C^\ast$ be its coordinate-swapped cycle

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 80

Let the given factorization be N = p_1^{e_1} p_2^{e_2} \cdots p_t^{e_t}.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 79

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 78

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 77

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 76

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 75

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4hard
CF 103964G - Ancient Go

We are given a rectangular board that resembles the game of Go. Each cell is either empty or contains a stone belonging to one of two colors. Stones that touch orthogonally form connected groups.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 74

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4hm-medium
TAOCP 7.2.1.1 Exercise 73

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 72

We are given a patient who may suffer from exactly one disease among $k$ candidates.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 71

Connection interrupted.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 70

The previous solution failed because it replaced the problem with an unsupported structural claim.

taocpmathematicsalgorithmsvolume-4medium
CF 104218C - Sled Circle

We have n dogs placed on n equally spaced points arranged in a circle. Dog i starts at position i at time 0, and each dog moves forward clockwise with a fixed step size vi every unit of time. Because movement is modular around the circle, positions are always taken modulo n.

codeforcescompetitive-programming
CF 104199L - Звезда в Отеле

We are maintaining a dynamic line of guests in an event hall. Each guest has a unique numeric identifier. The line supports three types of operations that continuously reshape its order. A guest can arrive with a declared “friend reference” to another guest.

codeforcescompetitive-programming
CF 104199K - Глючные робоанты

We are given an array that describes a starting arrangement of items on positions labeled from 1 to n. Position i initially holds item a[i], and the final goal is to transform this arrangement so that position i contains item i for every i.

codeforcescompetitive-programming
CF 104199I - Где же пицца??

The grid describes a hotel sign made of uppercase letters, where a hidden construction encodes a 5-letter hotel name twice in a very specific geometric way.

codeforcescompetitive-programming
CF 104199H - Номерки

We are given a key, which is an n-digit string, and we are asked to find all possible n-digit room numbers that are compatible with it under a set of digit-wise constraints.

codeforcescompetitive-programming
CF 104199F - Конвейерный отель

We have $n$ friends standing in a line of rooms numbered from 1 to $n$. Each friend initially holds a package that must be delivered to exactly one other friend, and every friend is both a sender and a receiver.

codeforcescompetitive-programming
CF 104199G - Приключение на 20 минут

We are given a linear corridor of doors arranged from left to right. Each door has a color, and every color appears exactly twice. The porter starts just to the left of the first door and wants to escape to the right of the last door.

codeforcescompetitive-programming
CF 104199E - Не все специи одинаково полезны

There are $n$ different spices in a kitchen, each identified by a name. A daily dish is prepared by choosing exactly $m$ distinct spices, but we do not know which ones were chosen.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 69

The earlier solution fails because it assumes a matrix structure that is never derived from the definition.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104197N - No Zero-Sum Subsegment

We are given a multiset of four types of moves that together describe a constrained walk on the integer line. Each type corresponds to a fixed step length and direction: some moves shift the position by 2 units to the left, some by 1 unit to the left, some by 1 unit to the…

codeforcescompetitive-programming
CF 104197J - Jewel of Data Structure Problems

We are given a permutation of size $n$, and it is modified through a sequence of swaps. After each modification, we need to compute a value called the “beauty” of the current permutation.

codeforcescompetitive-programming
CF 104197C - Count Hamiltonian Cycles

We are given a binary string of length 2n consisting of two types of vertices, W and B. We want to count Hamiltonian cycles over the 2n labeled vertices, but the cycle is constrained by a prefix-consistency condition: at every prefix i, the structure of how edges of the cycle…

codeforcescompetitive-programming
CF 104197M - Most Annoying Constructive Problem

We are working with permutations of the numbers from 1 to n. Every contiguous segment of length at least two contributes a binary value: we classify each subarray as either “even” or “odd” based on a parity rule defined in the problem (which ultimately behaves like…

codeforcescompetitive-programming
CF 104196H - Numble

We are given a small crossword-like board where most cells are either empty, already filled with digits, or special bonus cells. We also have a small set of digit tiles in hand.

codeforcescompetitive-programming
CF 104196J - Recycling

We are given a sequence of weekly estimates, where each number describes how many cubic meters of recyclable material will arrive in a specific week. We want to place a recycling bin for some contiguous range of weeks and choose its capacity.

codeforcescompetitive-programming
CF 104196G - Noonerized Spumbers

We are given a single arithmetic expression containing three integers written as strings, either in the form $x + y = z$ or $x times y = z$.

codeforcescompetitive-programming
CF 104178C - Now-Or-Never

I’m missing the actual problem statement for “Codeforces 104178C - Now-Or-Never”, so I can’t reliably reconstruct the intended solution or write a correct editorial.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 68

Let $\Sigma_n = {0,1,2}^n$.

taocpmathematicsalgorithmsvolume-4medium
CF 103964A - Secrete Master Plan

The problem as given does not describe any concrete input format or required transformation, so there is no computational structure to infer beyond the fact that the program is expected to produce an output without relying on any parsed data.

codeforcescompetitive-programming
TAOCP 7.2.1.1 Exercise 67

Let $a_0, a_1, \ldots, a_{2^{n-1}-1}$ be the Gray binary code on $(n-1)$ bits from Section 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 66

The previous solution failed for two independent reasons: a wrong state-space count and an imprecise formulation of what is actually being searched.

taocpmathematicsalgorithmsvolume-4project
TAOCP 7.2.1.1 Exercise 65

Let $B_5$ denote the Beckett state graph: vertices are pairs $(S,Q)$ where $S\subseteq\{1,2,3,4,5\}$ and $Q$ is the FIFO queue of $S$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 64

We restart from the actual structure of a Gray stream as a sequence of perfect matchings on the hypercube, and we avoid reducing the problem to an incorrect product or “state evolution” heuristic.

taocpmathematicsalgorithmsvolume-4hm-hard
TAOCP 7.2.1.1 Exercise 63

Let $\Gamma_n = g(0), g(1), \dots, g(2^n-1)$ denote the $n$-bit Gray cycle as defined in (5)–(7).

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 62

Let $\Gamma_n$ be an $n$-bit Gray cycle in the sense of Section 7.

taocpmathematicsalgorithmsvolume-4research
TAOCP 7.2.1.1 Exercise 61

The bit string $(13)$ refers to the binary representation displayed in equation $(13)$ of the section, a_{23}\dots a_1 a_0 = 011001001000011111101101, which represents an $(s,t)$-combination with $s=1...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 60

The bit string $(13)$ refers to the binary representation displayed in equation $(13)$ of the section, a_{23}\dots a_1 a_0 = 011001001000011111101101, which represents an $(s,t)$-combination with $s=1...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 59

Define the standard \(n\)-bit reflected Gray cycle \(C_n\) recursively as follows.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 58

Let $\alpha = (a_0, a_1, \dots, a_{2^n-1})$ be the delta sequence of an $n$-bit Gray cycle in the $n$-cube $Q_n$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 57

Let $Q_4$ denote the 4-dimensional hypercube graph whose vertex set is ${0,1}^4$ and whose edges connect vertices that differ in exactly one coordinate.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 56

The previous solution fails because it never produces a valid orbit enumeration.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.2.1.1 Exercise 55

The bit string $(13)$ refers to the binary representation displayed in equation $(13)$ of the section, a_{23}\dots a_1 a_0 = 011001001000011111101101, which represents an $(s,t)$-combination with $s=1...

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 54

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 53

Let $Q_n$ be the $n$-dimensional hypercube with vertex set ${0,1}^n$, where each edge is labeled by the coordinate in which its endpoints differ.

taocpmathematicsalgorithmsvolume-4math-research
TAOCP 7.2.1.1 Exercise 52

The previous argument fails only because it does not properly justify two key facts: (i) the projection onto the first $j$ coordinates is indeed surjective, and (ii) how this surjectivity forces a low...

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 51

The flaw in the proposed argument is that it tries to transfer coordinate symmetry of the hypercube into symmetry of a _particular recursively defined cycle_, without proving that the recursion produc...

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 50

Let $Q_n(l)$ denote the graph on $\{0,1\}^n$ where two vertices are adjacent iff they differ in exactly $l$ coordinates.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 49

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 48

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4hm-research
TAOCP 7.2.1.1 Exercise 47

The previous solution fails because it introduces an external structure (perfect matchings) that is not part of the information supplied by Exercises 44 and 46.

taocpmathematicsalgorithmsvolume-4hm-medium
TAOCP 7.2.1.1 Exercise 46

The previous attempt fails because it tries to “lift” a Gray cycle on $\{0,1\}^k$ into a block-selection rule without defining a consistent edge partition of the $(kr+2)$-cube.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 45

The previous argument failed because it treated the quotient construction in (b)–(d) as if it erased the combinatorial information carried by the internal perfect matchings.

taocpmathematicsalgorithmsvolume-4math-project
TAOCP 7.2.1.1 Exercise 44

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 43

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4project
TAOCP 7.2.1.1 Exercise 42

The failure in the previous solution is not local but structural: it replaced Algorithm L’s actual auxiliary state with an unrelated DFS-stack model and then argued about bit changes in that invented...

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.2.1.1 Exercise 41

The flaw in the previous solution is that it never connects the removed words to the actual image of the pairing construction in (23).

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 40

The key correction is that the question is not about reconstructing the letters from the modified masks in some abstract sense, but about whether the _unchanged W2 procedure_ still functions correctly...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 39

Let the 8 variables be indexed by $G={0,1}^3$, written $i=(i_1,i_2,i_3)$ with binary addition $i\oplus j$.

taocpmathematicsalgorithmsvolume-4hm-hard
TAOCP 7.2.1.1 Exercise 38

Let $\omega = e^{2\pi i/3}$, so $\omega^3 = 1$ and $1 + \omega + \omega^2 = 0$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.2.1.1 Exercise 37

Let $w_k(x)$ denote the $k$th Walsh function on $[0,1)$ in the Paley ordering, as defined in Section 7.

taocpmathematicsalgorithmsvolume-4hm-medium
TAOCP 7.2.1.1 Exercise 36

Let $X[0],X[1],\dots,X[n-1]$ be the array to be permuted, and let the inner loop in (42) denote the operation that is executed once per produced permutation, typically a visit or output of the current...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.2.1.1 Exercise 35

Let $x \in [0,1)$ and write its dyadic expansion x = 0.

taocpmathematicsalgorithmsvolume-4hm-medium