brain

tamnd's digital brain — notes, problems, research

41230 notes

TAOCP 7.1.3 Exercise 87

The solution does not correctly resolve the optimization problem.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 86

Let the array indices satisfy \[ 0 \le i < 2^p,\quad 0 \le j < 2^q,\quad 0 \le k < 2^r, \] with binary expansions \[

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 85

Let $i=(i_4 i_3 i_2 i_1 i_0)_2$, $j=(j_4 j_3 j_2 j_1 j_0)_2$, $k=(k_4 k_3 k_2 k_1 k_0)_2$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 84

Let $\chi$ contain exactly $2^d$ one-bits and let these bits occur at positions \chi = \sum_{j=0}^{2^d-1} 2^{p_j}, \qquad p_0 < p_1 < \cdots < p_{2^d-1}.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 83

Let $\chi$ be a mask with exactly $2^d$ one-bits.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 82

Let $\chi$ be a fixed set of nonnegative integers closed under the relation $x \subseteq \chi$, meaning every 1-bit position of $x$ corresponds to an element of $\chi$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 81

Let $\chi$ be a fixed set of nonnegative integers closed under the relation $x \subseteq \chi$, meaning every 1-bit position of $x$ corresponds to an element of $\chi$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 80

The solution does not address Exercise 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 79

The solution does not address Exercise 7.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 78

Each $x_j$ is a nonnegative integer with $x_j < 2^{n-k}$, hence each $x_j$ occupies at most the lowest $n-k$ bits.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 77

A mapping network on $n$ inputs uses $2\times 2$ modules, each module taking inputs $(a,b)$ and producing one of $(a,b)$, $(b,a)$, $(a,a)$, $(b,b)$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 76

A mapping network on $n$ inputs uses $2\times 2$ modules, each module taking inputs $(a,b)$ and producing one of $(a,b)$, $(b,a)$, $(a,a)$, $(b,b)$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 75

The solution targets the correct object: the cyclically shifted counts and the balance condition \sum c'_{2t}=\sum c'_{2t+1}.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 74

The solution targets the correct object: the cyclically shifted counts and the balance condition \sum c'_{2t}=\sum c'_{2t+1}.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 73

Let the $2^d$ bit positions be indexed by binary vectors $u = (u_{d-1}\ldots u_0)_2 \in {0,1}^d$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 72

Let the word size be $2^k$ bits, with bit positions indexed $0,1,\ldots,2^k-1$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 71

Let $\theta_0,\theta_1,\ldots,\theta_{d-1}$ be the masks used in compression procedure (80).

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 70

The solution does not correctly address what Steele’s problem is asking in the context of method (80).

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 69

The δ-shift operation (79) is the packed word transformation that produces a result $v$ from an input $u$ by forming a shifted copy of $u$ and combining it with $u$ by bitwise exclusive-or.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 68

The δ-shift operation (79) is the packed transformation on a word $u$ that shifts selected bit blocks by $\delta$ positions and combines results by XOR.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 44

Let $x = \sum_{j \ge 0} x_j 2^j$ with $x_j \in {0,1}$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 43

Let $w$ denote the word length of MMIX.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 42

Let $u = 2^{e_1} + \cdots + 2^{e_r}$ with $e_1 > \cdots > e_r \ge 0$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.1.3 Exercise 33

Let $y = 2^j + 2^k$ with $64 > j > k \ge 0$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 25

Each volume consists of 250 sheets of thickness $0.1\ \text{mm}$ each, so the total paper thickness per book is 250 \cdot 0.

taocpmathematicsalgorithmsvolume-4simple
TAOCP 7.1.3 Exercise 24

The failure is fundamental: all control flow in the proposed program is broken because it writes comparison results into register $0$, which is architecturally constant zero in MMIX and cannot be assi...

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 23

Encode “(” as $0$ and “)” as $1$.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 207

The reviewer is correct that the previous solution failed at the logical foundation: it _asserted_ multiplication by $21$ without deriving it from the shuffle.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 206

Let the input word $z$ be split into two halves $x$ and $y$, each consisting of 32 bits, so that $z = (x,y)$ in concatenated form.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 202

The previous solution fails for a structural reason: it replaces the required _wydewise predicate_ w \mapsto [w\neq 0]\cdot \#ffff with bytewise reasoning and then assumes a non-existent “merge-to-wyd...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.1 Exercise 129

Let $C_n$ denote the number of canalizing Boolean functions on $\{0,1\}^n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104380F - Double-Ended Queue

We are given a sequence of numbers that must be inserted one by one into a deque. Each number can be placed either at the front or at the back, and once placed, its position is fixed.

codeforcescompetitive-programming
CF 104380D - Primewords Revisit

We are constructing a digit string of length $n$, where each position can independently take a value from 0 to 9.

codeforcescompetitive-programming
CF 104380C - Number Machine

We start with a machine that stores a single integer, initially equal to 1. Two operations are allowed. One operation multiplies the current value by 3 and then adds 2, and the other operation simply increases the value by 1.

codeforcescompetitive-programming
CF 104380A - 01 (Easy Version)

We are given a binary string consisting only of characters 0 and 1. We are allowed to repeatedly find any adjacent pattern "01" and remove it completely from the string, closing the gap left by the deletion.

codeforcescompetitive-programming
CF 104381N - Hopscotch

This is no longer a parsing or I/O issue. The program runs and produces a value (29), but it is mathematically wrong. Let’s trace what the structure of the input implies: The first line strongly suggests: - N = 2, M = 3 Then we have multiple rows of paired data.

codeforcescompetitive-programming
CF 104381M - Friendship

We are given a line of people indexed from 1 to n. Each person i defines a range of other people they “know” based on their position: they know everyone whose index lies between i minus ai and i plus bi, inclusive.

codeforcescompetitive-programming
CF 104381L - Walking to School

We are given a directed or undirected graph of crossings connected by paths. Each path has a snow depth value, and Michael starts at crossing 1 and wants to reach a target crossing T. The twist is that his walking cost is not additive in the usual sense.

codeforcescompetitive-programming
CF 104381G - Anti-Gravity Boots

The failure here is not coming from the mathematical idea, but from execution flow. For the input: the correct output is 5, which matches the standard “count ordered pairs (i, j) where a[i] is divisible by a[j]”.

codeforcescompetitive-programming
CF 104381K - Hopscotch (Easy Version)

We are given two parallel rows of numbered tiles, each row containing $n$ positions. At every index $i$, the left row has a value $ai$ and the right row has a value $bi$.

codeforcescompetitive-programming
CF 104381J - Rash Cloyale

We are given two equal-sized groups of players, each containing $n$ people. Every player has a rating. The organizers will split players into two fixed groups A and B, but the pairing is flexible: each person in A must be matched with exactly one person in B, forming $n$ 2v2…

codeforcescompetitive-programming
CF 104381I - Line up

We are given a sequence of length $n$, and we want to decide whether it could have been produced from some hidden permutation of $1$ to $n$.

codeforcescompetitive-programming
CF 104381H - Grocery Shopping

We are asked to find the smallest integer that Michael can pay such that it is at least a given value $N$, but with a digit constraint on the payment itself. The constraint is purely about the decimal representation of the number we choose.

codeforcescompetitive-programming
CF 104381F - Hello World!

We are given a small array of integers, and we want to count how many ordered triples of indices $(x, y, z)$ satisfy the condition that the product of the two chosen elements equals a third element in the array.

codeforcescompetitive-programming
CF 104381E - Password Guessing

We are tracking a randomized password system that evolves week by week. There is a fixed list of $n+1$ distinct passwords. At the start, in week 1, the system uses the first password in the list. Each week, the password either stays the same or changes.

codeforcescompetitive-programming
CF 104381C - Bashy Math

We are given a collection of integers and we want to count ordered relationships between indices based on divisibility. For every pair of positions $i$ and $j$, we check whether the value at $i$ is divisible by the value at $j$, while ensuring the two indices are different.

codeforcescompetitive-programming
CF 104381D - Star Trek Wall

We are given a small set of axis-aligned rectangular posters placed on a fixed 20 by 20 grid that represents a wall. Each poster covers every cell inside its rectangle, and multiple posters may overlap.

codeforcescompetitive-programming
CF 104381A - Battleship

We are given a square game board of size $n times n$, where each cell is either ocean or a ship. A single query is made: a pair of coordinates $(r, c)$ representing a guessed cell on this board. The task is to determine what exists at that exact position.

codeforcescompetitive-programming
CF 104381B - Knishop

We are given two points on an infinite grid with integer coordinates. A piece starts at the first point and needs to reach the second point. In one move, the piece can behave in two different ways.

codeforcescompetitive-programming
CF 104385K - Split

We are given a sequence that starts out sorted in non-increasing order. The sequence is dynamic, because we are allowed to perform point updates of a very specific form, and we must also answer queries about how best to split the array into contiguous segments.

codeforcescompetitive-programming
CF 104385L - Zhang Fei Threading Needles - Thick with Fine

We are given a single integer $N$, representing the number of soldiers in Cao Cao’s army positioned in front of Changban Bridge. The story describes Zhang Fei’s roar causing panic and making soldiers flee.

codeforcescompetitive-programming
CF 104385H - Permutation

The crash happens before any algorithm runs: Your program is assuming a multi-line format with three integers in the first line, but the actual input is: So: - First line contains only N - Second line contains the array - There are no M, Q, or query lines at all This is not a…

codeforcescompetitive-programming
CF 104385J - Function

We are maintaining a dynamic collection of quadratic functions, all sharing the same shape but shifted along the x-axis and vertically offset. Each function looks like a parabola with fixed curvature 1, centered at some integer position, and then shifted up by a constant value.

codeforcescompetitive-programming
CF 104385I - Tree

We are given a tree where each edge carries an integer value. The tree is fixed, but the edge values change over time. The system supports two operations.

codeforcescompetitive-programming
CF 104385F - Cities

We are given a line of cities labeled from 1 to n, each placed at a distinct coordinate on a number line. Adjacent cities are connected by a road, so initially the graph is just a chain.

codeforcescompetitive-programming
CF 104385G - Copy and Paste

We are given a target lowercase string and an initially empty workspace. The goal is to construct the string using the fewest possible operations under a very specific toolset: we can append a single character to the end of the current text, we can copy the entire current text…

codeforcescompetitive-programming
CF 104385B - Wonderful Array

The crash happens before any algorithm runs: Your program is assuming a multi-line format with three integers in the first line, but the actual input is: So: - First line contains only N - Second line contains the array - There are no M, Q, or query lines at all This is not a…

codeforcescompetitive-programming
CF 104385E - Segment-tree

We are given a complete segment tree over the range from 0 to 2^n − 1. Instead of working with the array directly, the problem constructs an induced graph G by running a segment tree query procedure on an interval [L, R].

codeforcescompetitive-programming
CF 104385D - Stack Out

We are generating sequences of operations on a stack that processes the numbers from 1 to n in increasing order. At any moment, we either take the next unused number and push it onto the stack, or we pop the current top of the stack if it is not empty.

codeforcescompetitive-programming
CF 104385C - Battle

We are given several piles of stones. Two players take turns, and on each turn a player selects exactly one pile and removes a number of stones from it.

codeforcescompetitive-programming
CF 104385A - Drill Wood to Make Fire

We are given a very small simulation repeated multiple times. Each test case describes a scenario where a person is trying to generate fire by drilling wood.

codeforcescompetitive-programming
CF 104386G - CLC Loves SQRT Technology (Hard Version)

We are given an array and we look at every possible non-empty subsequence of it. For each subsequence, we want to know the minimum number of elements we must overwrite so that the subsequence can be turned into a palindrome.

codeforcescompetitive-programming
CF 104386F - CLC Loves SQRT Technology (Easy Version)

We are given a sequence of numbers, and we look at every possible non-empty subsequence. For each chosen subsequence, we are allowed to perform an operation where we pick any element in it and overwrite its value arbitrarily.

codeforcescompetitive-programming
CF 104386B - Random Array

We want the k-th smallest element in a multiset formed by: - X: values xi each repeated si times - Y: values transformed per query as alpha yj + beta, each repeated tj times We never expand arrays. Instead, we answer: how many elements are ≤ v?

codeforcescompetitive-programming
CF 104386D - Comic Numbers

We are asked to count integers inside many large intervals that satisfy a specific divisibility rule tied to their cube root. For any positive integer $x$, we compute $k = lfloor sqrt[3]{x} rfloor$, and we call $x$ valid if it is divisible by $k$.

codeforcescompetitive-programming
CF 104386E - Gridy

We are given a rectangular grid where each cell already contains either a fixed 0, a fixed 1, or an unknown ?. Every unknown cell will later be independently replaced by either 0 or 1, each choice having equal probability.

codeforcescompetitive-programming
CF 104386A - Dungeon videogame

We are given several independent dungeon runs. Each run consists of a sequence of levels, and at each level we must make exactly one choice: either we clear the level and gain the value written on it, or we skip a contiguous block of levels and pay a penalty equal to the…

codeforcescompetitive-programming
CF 104386C - Prefix Sum Array

We start with an infinite array where every position initially contains the value 1. Each second, the array is replaced by its prefix sum version, meaning the value at position i becomes the sum of all values from position 1 to i in the previous array.

codeforcescompetitive-programming
CF 104390A - Merge

Two people report charging stations along a line. Each station has a position and a number of outlets. We effectively build a multiset of positions where each position appears multiple times according to how many outlets exist there. Mr.

codeforcescompetitive-programming
CF 104390C - Jewelry Necklace

We are given a binary string representing a line of suppliers. Each position contributes either a real gemstone or a fake one. A necklace is formed by choosing any contiguous segment of this string.

codeforcescompetitive-programming
CF 104390B - Explorer

We are given a tree with $N$ rooms. Alongside the tree structure, we also receive a long sequence of length $2N-1$, which comes from an older exploration process that behaves like a depth-first traversal but records visits differently: every time a room is entered, its label…

codeforcescompetitive-programming
CF 104391B - Phitsanulok

We are given a collection of fruits. Each fruit has a weight and a description over up to 19 poison types. For every poison type, a fruit can either contain that poison, contain the antidote for it, or contain neither.

codeforcescompetitive-programming
CF 104391C - Range

We are given a collection of intervals on the number line, each interval representing a “mountain” with a left endpoint and a right endpoint.

codeforcescompetitive-programming
CF 104391A - Energy

We are given a sequence of energy cell values laid out in a line. The machine we need to feed has a fixed perfect binary tree structure with $K$ layers, so it contains $2^{K-1}$ leaves at the bottom and a total of $2^K - 1$ nodes.

codeforcescompetitive-programming
CF 104508D - Decision Problem

We are given a sequence of integers. There is no second line, no graph structure, and no hidden parameters. The task is to compute a single integer output from this array.

codeforcescompetitive-programming
CF 104412C - Choose Two

Your result “1” corresponds to assuming: every configuration contributes exactly 1 cycle deterministically So the code is effectively treating the structure as if cycles are always fully formed, which is wrong.

codeforcescompetitive-programming
CF 104412N - Necklace

We are given a circular necklace represented as a linear array of pearls, where each position has two attributes: a value and a type.

codeforcescompetitive-programming
CF 104412M - Modify the Array

We are given a permutation of numbers from 1 to n, and we are allowed to repeatedly compress any contiguous segment into a single value equal to the minimum element in that segment.

codeforcescompetitive-programming
CF 104412E - Earnings Report

We are given a collection of jobs, each of which pays a fixed amount repeatedly over time according to a deterministic calendar rule.

codeforcescompetitive-programming
CF 104412H - How Many Groups

We are given a company hierarchy that forms a rooted tree. Each employee has exactly one direct supervisor except for the top-most manager, who has none.

codeforcescompetitive-programming
CF 104395F - Cycles

Now we finally have a clean arithmetic discrepancy, not a parsing failure. The program is correctly producing most outputs, but one value is off: So the structure is correct, input is correct, and indexing is correct.

codeforcescompetitive-programming
CF 104395C - String Keyboard

We are given a line of N distinct keyboard keys, each labeled with a unique uppercase letter. We want to construct a string by repeatedly “pressing” keys, but the key action is slightly unusual: pressing an internal key produces a pair of adjacent characters, namely the…

codeforcescompetitive-programming
CF 104395A - Cow Treats

We are given a chronological log of a barn where cows repeatedly enter and leave. Each line of input describes a single event for a specific cow: if the cow is currently outside, the event means it enters; if it is currently inside, it leaves.

codeforcescompetitive-programming
CF 104393B - BWS Baker Web Service

Now we finally have a clean, precise failure mode: at: This is not an arithmetic bug or logic bug. It is a hard desynchronization of the input parser.

codeforcescompetitive-programming
CF 104393I - Improving the Neighborhood

We are given a small grid representing a neighborhood. Each cell is either a wall, a free traversable tile, a house, a school, or a park.

codeforcescompetitive-programming
CF 104393E - Elisa's Melodies

We are asked to count how many different melodies a constrained “random-walk” system can produce on a circular keyboard. There are $N$ keys arranged in a ring. A melody starts from a fixed key $S$.

codeforcescompetitive-programming
CF 104393H - Harvesting Apples

We are given a row of baskets, each basket having a fixed maximum capacity. Over a sequence of days, apples are harvested and assigned to exactly one basket per day. When apples are added to a basket, the basket can never exceed its capacity.

codeforcescompetitive-programming
CF 104393F - Funny Numbers

We are given a function on integers that repeatedly transforms a number by replacing it with the sum of squares of its digits. Starting from a number $N$, we apply this transformation repeatedly, producing a sequence like $N, F(N), F(F(N)), dots$.

codeforcescompetitive-programming
CF 104393A - Acrobatic Jumping

We are simulating a constrained movement process on a straight line segment of length $N$. Amy starts at position 0 and must eventually reach position $N$.

codeforcescompetitive-programming
CF 104393D - Destroying Asteriods

We are given a vertical grid with many rows and columns, but almost all cells are empty except for one asteroid in each column. Column $i$ contains exactly one asteroid placed at row $ci$.

codeforcescompetitive-programming
CF 104412I - Iron Fist Ketil vs King Canute

We are given two groups of people facing each other in a one-time battle. One side has Ketil’s farmers, the other has Canute’s soldiers.

codeforcescompetitive-programming
CF 104412A - Alaric Magic Partition

We are given a long digit string, and we are allowed to carve it into several disjoint contiguous pieces. Each chosen piece is interpreted as a decimal number, and it is only considered valid if that number is either a prime or a perfect square.

codeforcescompetitive-programming
CF 104400H - Contest Simulation

We are given a programming contest log and need to reconstruct the final ranking of participants under ICPC-like rules, then print the ranking with medal separators. Each participant has a stream of submissions across up to 20 problems.

codeforcescompetitive-programming
CF 104400A - Playf and ABC

We are given a string consisting only of the characters A, B, and C. From this string, we want to extract as many disjoint triples of indices as possible.

codeforcescompetitive-programming
CF 104400L - Timetable Queries

We are given a one-day timetable of length n, where each minute has exactly one bus arriving and each arrival is labeled with a bus number. So the input array is a sequence of identifiers, and the i-th value tells us which bus arrives at minute i.

codeforcescompetitive-programming
CF 104397K - Da Capo

We are given a rectangular 3D region with dimensions $w times h times l$. The task is to completely partition this volume into a set of smaller axis-aligned boxes such that they exactly fill the original space without overlaps or gaps. Each small box is not arbitrary.

codeforcescompetitive-programming
CF 104397B - Poker Number

We are given a range of numbers from 1 to $n$. Some of these numbers are “special”: they are called Poker Numbers if they can be written as a positive multiple of a triangular number of the form $Tx = frac{x(x+1)}{2}$, where $x ge 2$.

codeforcescompetitive-programming
CF 104397J - Billboard

We are given a ranked list of songs, where each song initially sits at a unique position from 1 to n. For every song, we receive exactly one consolidated opinion about whether its current position is acceptable or should be changed.

codeforcescompetitive-programming
CF 104397I - W-shaped Rail Fence Cipher

We are given a string that needs to be rearranged according to a fixed “W-shaped” writing path. Instead of writing characters left to right in a single line, we imagine placing them along a vertical pattern with multiple rows, then reading them row by row.

codeforcescompetitive-programming
CF 104397H - Morning ECO, Evening EMO

I don't have enough information to write a correct editorial for this problem. The prompt identifies Codeforces 104397H - Morning ECO, Evening EMO, but the essential parts are missing: - Problem statement - Input specification - Output specification - Constraints - Sample…

codeforcescompetitive-programming