brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given two equal-length strings over the lowercase alphabet. The allowed move is not a local edit but a global relabeling: we pick two distinct letters, and every occurrence of those two letters in the string is swapped simultaneously.
We are given two sequences, each a permutation of the same set of integers from 1 to n. The task is to find the length of the longest subsequence that appears in both permutations and is strictly increasing.
We are given a tree with n vertices, each vertex carrying a non-negative weight. We need to split the vertices into disjoint groups, where each group must form a simple path in the tree, and no vertex can belong to more than one group.
We are given a multiset of positive integer weights representing soldiers. The only operation allowed is to take two soldiers whose strengths differ by exactly one and replace them with a single soldier whose strength is their sum.
We are given a sequence of integers from 1 to n placed in a row. Two players alternate moves, starting with the first player.
We are given a positive integer $k$, describing a stack of $k$ consecutive square layers. The base layer contains $n^2$ cannonballs, the next contains $(n+1)^2$, and so on up to $(n+k-1)^2$. The total number of cannonballs is therefore the sum of these $k$ consecutive squares.
We are interacting with a hidden positive integer $x$. Instead of seeing it directly, we can submit queries with a number $q$, and the judge replies with a value derived from the integer $leftlfloor frac{x}{q} rightrfloor$.
We are given a rectangular grid where each cell behaves like a directed system. Most cells are normal, meaning stepping onto them simply costs one hour per move.
We are moving on a graph whose vertices are integers greater than 1. From any integer $u$, we may move to any other integer $v$, and the cost of that move is $mathrm{lcm}(u, v)$.
The input describes a set of axis-aligned rectangles on an infinite grid. After applying all of them, every grid cell covered by at least one rectangle becomes “bare”.
We are given an ordered set of points on a number line. At each step, Bob picks two adjacent points in the current ordering, removes them, and inserts their midpoint.
We are asked to construct a permutation of the numbers from 1 to n such that a particular cost expression becomes as small as possible.
Working
We are dealing with a hidden binary string of length n. We cannot see it directly. Instead, we are allowed to submit a constructed binary string T of the same length, and the judge returns a single number: the count of positions where S XOR T equals zero.
Working
The structure is a rooted tree with node 1 acting as the root, but conceptually it is drawn upside down so that gravity pushes objects toward the root. Each node can hold at most one ball. We are given a sequence of starting nodes, and we drop balls one by one.
We are given a binary string and two ways to modify it, each with a cost. The goal is to transform the string into a “good” form where no adjacent pair of characters differs.
We are simulating a simplified cricket scoring system where each ball contributes a fixed amount of runs. The batsman can only score either 4 or 6 runs per ball, and we want to reach at least a target score $n$.
The statement you provided is effectively empty beyond the contest header, so there is no information about the task itself (no input format, no required output, no constraints, and no problem definition).
We are given a collection of water reservoirs. Each reservoir has a fixed capacity and a current amount of water stored inside it. The operation allowed is very specific: we may choose at most two reservoirs, say i and j, and pour all water from j into i.
Solution to TAOCP 7.1.3 Exercise 215.
A complete branchless solution must make the pivot selection explicit.
Let $a = (a_{63}\dots a_1 a_0)_2,\qquad b = (b_{63}\dots b_1 b_0)_2,$ and interpret them as polynomials over $\mathbb{F}_2$, $a(x)=\sum_{i=0}^{63} a_i x^i,\qquad b(x)=\sum_{j=0}^{63} b_j x^j.$ The pro...
Index the $64$ entries of $f$ by vectors $x = (x_1,\dots,x_6) \in {0,1}^6$, and write \hat f(x) = \bigvee_{y \le x} f(y), where $y \le x$ means $y_i \le x_i$ for all $i$, so $\hat f$ is the least mono...
Let $x$ contain $8j+k$ with $0 \le j,k < 8$.
The earlier solution fails because it tries to reconstruct hidden structure using $y \mathbin{\&} (-y)$, which only isolates the least significant 1-bit and does not encode any run length information.
The solution must address the actual object in Exercise 36, namely the suffix parity transformation $x^{\oplus}$, and relate it to what MXOR can compute.
The previous construction fails because it tries to realize the transpose as swaps at fixed index distances in the full 64-bit linearization.
We are given a string made only of digits 2, 3, 4, and 5, which represents a sequence of grades in a school journal. We are allowed to modify any character, but only by increasing its value, never decreasing it.
We are given a directed structure where each story points to exactly one other story. Formally, each index i has a single outgoing edge to a[i]. We also have a binary array b, where b[i] = 1 means Bunga believes story i was told, and b[i] = 0 means he believes it was not told.
We are simulating a process where shirts arrive one by one from the top of a stack and are placed onto a linear hanger with positions from 1 to n.
We are given a multiset of $2n-1$ positive integer weights, representing cheese pieces. We are allowed to choose exactly one of these pieces and cut it into two positive real parts. After this operation, we have exactly $2n$ pieces in total.
We are given a vertical stack of circular bread slices, all centered on the same vertical line. Each slice is a cylinder of height 1 and radius r[i]. The first slice touches the table, the second sits on top of the first, and so on.
We are placing rooks on an $n times n$ chessboard, but unlike the classical rook-placement problem, we are allowed to tolerate conflicts. A rook attacks along its row and column, so two rooks in the same row or column attack each other.
We are given a multiset of points placed on a number line. At each step, we repeatedly pick any two existing points, remove them, and insert their midpoint. This continues until only one point remains, and the process stops.
We are given a fixed tree, and every vertex starts in one of two states that change over time. Initially, all vertices are white. Each operation selects two vertices and paints every vertex on the unique path between them black. Once a vertex becomes black, it never changes back.
We are given a large grid, but only a small number of cells actually contain fish. Each such cell can contain up to three fish.
We are simulating a simplified Go game on a fixed 19×19 grid, where stones are added one by one and never removed except when they become “dead”.
We are given an array of integers where each value represents the initial level of an enchanted book. Books are placed in a fixed order, and several types of operations are performed over this array.
We are given a sequence of chapter costs, and we must split this sequence into at most $k$ contiguous segments, where each segment corresponds to a day of reading.
Each test case describes a simple catering plan for a programming contest. There are $n$ contestants in total. Exactly $x$ of them choose a grilled chicken burger set, while the remaining $n - x$ choose a spicy chicken burger set.
We are given two positive integers $x$ and $y$. From these two values we compute their greatest common divisor and least common multiple, and then form a derived quantity that combines them through a square root.
We are given several independent test cases. In each one, we receive up to 100 points on a 2D plane. From these points, we are allowed to choose any subset and look at the convex polygon formed by the chosen points as its vertices.
The original solution fails because it does not implement the correct byte insertion into the polynomial register and therefore does not preserve the CRC invariant.
We are given a geometric graph where each vertex is a point on a plane and edges connect some pairs of these points. The edges are guaranteed to form a forest, so each connected component is already a tree in the full graph. We then take a random axis-aligned rectangle.
The grid describes a floor plan where each boundary segment between cells can either be a fabric wall or a normal wall. Lorenzo is initially stuck on one specific fabric wall segment, meaning he is attached to a particular cell boundary with a known orientation.
We are given a set of competing teams in a contest. Each existing team has three attributes: their strength, their weight, and the difficulty of the problem they contributed.
We are given a group of people, each with a target final value $ai$. Initially every person starts at zero. There is a global operation that is applied in steps: each time the group “takes a shot”, every person updates their current value using the same rule.
We are given a line of slot machines, each containing some number of stones. For any contiguous segment of machines, indexed from l to r, a two-player game is played on that segment.
We are given a sequence of operations that simulate a very simple memory system. Each variable is allocated exactly once using a let X = new(); statement, and later released exactly once using drop(X);.
We are given a timeline of production that is already split into disjoint time intervals. Each interval produces containers of a single product type, and during every unit of time inside that interval exactly one container appears.
We are given a circular cake centered at the origin with a fixed radius. Inside this cake, there are several candles placed at integer coordinates, and every candle lies strictly inside or on the boundary of the circle.
We are given a directed graph with $n$ nodes and $m$ unit-length edges. We also have $k$ independent construction teams.
We are given a row of vertical pillars of width 1, each with a distinct height. At both ends of the row there are imaginary pillars of infinite height, which act like absolute walls. For each query, water is dropped from infinitely high above a chosen pillar.
We are given a binary string and allowed to repeatedly perform a very flexible operation: pick any contiguous segment and rotate it cyclically.
We are given two types of items. There are n items of type A, each contributing value a, and m items of type B, each contributing value b. We want to repeatedly assemble identical “products”.
We are given a hidden $n times n$ grid filled with positive integers in the range $[1, n^2]$. The grid is not arbitrary: values are monotone in both directions, meaning they never decrease as we move right or down.
We are given a tree where a “fake message” starts at a fixed node $r$ and spreads outward one edge per unit time. At time $t$, every node within distance at most $t$ from $r$ has received it, so the infected set is exactly a metric ball centered at $r$.
We are standing on a line of seats, each seat holding a non-negative value. From a chosen starting seat, we may move left, right, or stay in place once per second. Whenever we land on a seat for the first time, we collect its value. Re-visiting a seat later gives nothing new.
We are given a rooted tree with node 1 as the root. Each move lets us pick a node $u$, detach it from its parent, and then perform a “leaf pruning” process inside the component rooted at $u$.
We are given an array of non-negative integers and a very flexible operation that allows us to move any amount of value from one position to another, as long as no element becomes negative.
We are asked to construct a string of decimal digits whose length does not exceed one hundred thousand, but the string is not arbitrary. The requirement is tied to all longest strictly increasing subsequences of that string.
We are given a tree with weighted nodes. The tree is undirected and can be rooted at any node we choose. Once a root is fixed, every other node has exactly one parent defined by the rooted tree structure.
We are asked to construct an $n times n$ binary grid, where each cell is either a mine or an empty cell. The grid must contain exactly $m$ mines.
We are given a rooted tree with root at vertex 1. Every non-root node has a parent, and each edge from a node to its parent has a non-negative weight. We must assign to every vertex a distinct integer from 1 to n, forming a permutation of the vertices.
We are given a continuous range of integers from L to R, where each integer represents a material. From this range, we must choose two materials (they may be the same) and compute a score based on how different their decimal representations are.
We are given a permutation of size n, representing numbers placed in n cells in a line. The goal is to understand how many times we must “reset” a special typing machine in order to restore the permutation into the identity arrangement where number i sits in cell i, but we…
Let the perfect shuffle of Exercise 204 be the MMIX program obtained in (175)–(178), using constants $p, q, r, m$, and let it map an input register state $z$ to an output state $w$.
The failure in the previous construction comes from a false invariant: masking with x \,\&\, 0xFFFFFFFF00000000 does not produce a normalized 32-bit quantity.
We restart from the actual MMIX semantics used in TAOCP.
Let $x = (x_{15}\ldots x_1 x_0)_{16}$, where each $x_i \in {0,\ldots,15}$ is a hexadecimal digit.
In MMIX, register $0$ is the constant zero register, so its contents are $0$.
Let $x>0$ and define $u = x \,\&\, (-x), \qquad v = x + u.$ Let $k$ be the unique index such that $u = 2^k$.
We restart from the actual existence condition.
Let $l$ be the number of bytes in the UTF-8 encoding of $x$.
Let $x$ be a codepoint in $0 \le x < 2^{20}+2^{16}$.
The solution must be rebuilt from the actual definitions, not from byte-range heuristics.
Let $A$ be the binary matrix with rows $\alpha_1,\ldots,\alpha_m \in {0,1}^n$.
Let $A=(a_{i,j})$ be a perfect $m\times n$ parity pattern, so for every $i,j$, a_{i,j}\equiv \sum_{j'\ne j} a_{i,j'}+\sum_{i'\ne i} a_{i',j}\pmod 2, and no row or column of $A$ is identically zero.
We are given a rectangular cake modeled as an $n times m$ grid. Inside this grid there are $k$ distinct cells, each containing exactly one candle.
We restart from the actual combinatorial structure of parity patterns and only use identities for Fibonacci polynomials that can be derived directly from their defining recurrence.
Work in the ring R=\mathbb{F}_2[x,x^{-1}]/(x^N+1), \qquad N=2n+2, so that $x^{-1}=x^{N-1}$.
We correct the solution by rebuilding the argument from the linear structure of the parity condition and avoiding any invalid submatrix or periodicity assumptions.
Each student in the classroom is associated with a range of topics they understand. If the teacher asks about a topic, every student either reacts positively if the topic lies inside their learned interval or negatively if it lies outside.
Let the bitmap be stored as $8$ consecutive rows of bytes per block column.
The failure in the previous solution is fundamental: the bitmap is 1-bit packed, so each pixel must be extracted by bit operations, not by byte-wise `LDB` interpretation.
We are given two strings of equal length. One player can freely change any character of either string at any time, while the other player can flip a whole string end to end in a single move.
The failure in the previous solution is the assumption that the right subsegment must be explicitly stored.
Let B(t) = (1-t)^2 z_0 + 2(1-t)t z_1 + t^2 z_2, \qquad 0 \le t \le 1.
Let the endpoints be rational numbers (\xi,\eta)=\left(\frac{a}{c},\frac{b}{c}\right), \qquad (\xi',\eta')=\left(\frac{a'}{c'},\frac{b'}{c'}\right), where $a,b,a',b' \in \mathbb{Z}$ and $c,c' \in \mat...
Let Algorithm T be applied to the endpoints $(x,y)$ and $(x',y')$ with quadratic form $Q$, producing a sequence of edges determined by the sign changes of $Q$ along the digitized path from $(x,y)$ to...
Let $F(x,y)$ be the integer-valued function defining the conic, as in Algorithm T.
Let F(x,y)=ax^2+bxy+cy^2+dx+ey+g define the conic, and let the algorithm operate on a segment of the curve on which, say, $x$ is strictly increasing (the other case is symmetric).
Let the conic be given by F(x,y)=ax^2+bxy+cy^2+dx+ey+f=0,\qquad a,b,c,d,e,f\in\mathbb{Q}.
Let F(x,y)=y^{2}-x^{2}-13.
We are given a set of points in the plane, and for every pair of points we can measure two different distances: the Manhattan distance, which adds absolute horizontal and vertical displacement, and the Euclidean distance, which is the straight-line distance.
We are given a single integer $n$, and we want to split it into an ordered pair of positive integers $(a, b)$ such that $a + b = n$.
We are given a circular sequence of typed brackets, where each element is an integer. A positive value represents an opening bracket of a certain type, and the corresponding negative value represents its matching closing bracket.
We are given a graph with stations as vertices and tunnels as undirected edges. Each station has a cost, and we also have a modulus value $k$. For any chosen starting station $s$, we consider all stations that are reachable from $s$ using at most $d$ edges.
Let the columns of the original bitmap $X$ be indexed by $0,1,\ldots,N-1$.