brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105067C - Unique Subsequences

We are given a string and a number $k$. From the string, we look at all subsequences that have exactly length $k$. The question is whether any two different ways of choosing positions in the string can produce the same resulting length-$k$ sequence of characters.

codeforcescompetitive-programming
CF 105067B - Richard Lore

We are given an array of length n and a fixed sequence of swaps. Each swap exchanges two positions in the array, and this sequence is always applied in the same order.

codeforcescompetitive-programming
CF 105067D - Sleepy Pandas

We are given an array of numbers, each number representing a panda’s label. For any ordered pair of distinct indices $(i, j)$, we form a new number by writing $xi$ directly followed by $xj$.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 56

Number the bits of the 64-bit register from $0$ (least significant) to $63$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 55

The previous solution fails because it never instantiates a valid TAOCP register program: it introduces informal “tensor elimination”, undefined data layouts, and unsupported cost sharing.

taocpmathematicsalgorithmsvolume-4hard
TAOCP 7.1.3 Exercise 54

Let $d=\lceil \lg m\rceil$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 53

Let $\upsilon$ be a permutation of ${0,1,\ldots,d-1}$, and let $j = (j_{d-1}\ldots j_1 j_0)_2$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.1.3 Exercise 52

Let scheme (71) be interpreted in its actual routing form: for each stage $k\in\{0,\dots,5\}$, the exchange operates on the $k$-th bit position, and the masks must be chosen so that a datum located at...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 51

Let the butterfly network (71) act on bit strings $x \in \{0,1\}^d$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 50

The proof must avoid any assumption that arbitrary integers can be freely “normalized” into powers of 3.

taocpmathematicsalgorithmsvolume-4math-project
TAOCP 7.1.3 Exercise 49

The previous solution failed because it never used the actual structural property of δ-swaps and introduced unrelated complexity measures.

taocpmathematicsalgorithmsvolume-4math-hard
CF 105067F - Another Bitwise Problem

We are given an array and a variable integer $x$. For any choice of $x$, we compute a value by XORing $x$ with every array element and summing the results. This produces a single integer $S(x)$.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 48

The previous solution fails because it replaces δ-swaps by XOR translations on indices, which is unrelated to Knuth’s construction.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.1.3 Exercise 47

Let δ be the mask selecting the positions to be swapped in the general δ-swap (69).

taocpmathematicsalgorithmsvolume-4simple
CF 105067A - It's Time to Submit

The task reduces a contest joke into a binary decision. We are given a single integer $T$, but the important part is not the value itself, it is the meta-information: we are asked whether it is possible to obtain a correct solution submission simply by printing the sample output.

codeforcescompetitive-programming
CF 105071I - Oh It's XOR

We are given an undirected graph where each vertex carries an integer value. The task is not to compute anything over all paths in the usual shortest-path sense, but instead to consider all simple paths in the graph, pick any one of them, take the XOR of the vertex values…

codeforcescompetitive-programming
CF 105071K - Vote Here!

The problem gives us a single line of input that represents a user's feedback or selection of their favorite problem. The actual content of this line does not influence any computation. The task is to produce a fixed response regardless of what the input string contains.

codeforcescompetitive-programming
CF 105071D - Prestige Hunter

We are given a fixed reference list of company names ordered by prestige, where position 1 corresponds to the most prestigious company. Each query consists of a company name, and we must determine whether that name appears in the reference list.

codeforcescompetitive-programming
CF 105071G - :wink:

I don’t have the actual statement of Codeforces 105071G (“:wink:”) available from your prompt, so I can’t safely reconstruct the problem or write a correct editorial without risking inventing details.

codeforcescompetitive-programming
CF 105071F - Those Who Know

The task gives a single string of length up to one hundred thousand characters and asks for another string as output. There is no transformation rule described in a structured way such as parsing, filtering, or reordering.

codeforcescompetitive-programming
CF 105071E - Something's Fishy

The problem presents two quantities defined through limits, infinite sums, and definite integrals, and asks for a single integer derived from them. The final output is the floor of the hypotenuse of a right triangle whose legs are these two quantities.

codeforcescompetitive-programming
CF 105069O - 至少一半要相等

We are given an array of integers and we need to output a positive integer with a very specific property: when you reduce every array element modulo this integer, at least half of the elements land in the same residue class.

codeforcescompetitive-programming
CF 105069M - 染色游戏(easy version)

We are given a rectangular grid where each cell already has a color assigned to it. The game involves repeatedly applying painting operations, where each operation paints an entire row or an entire column with a single color, overwriting whatever was there before.

codeforcescompetitive-programming
CF 105069N - 染色游戏(hard version)

The task describes a grid coloring process where operations repaint entire rows or entire columns, overwriting previous colors.

codeforcescompetitive-programming
CF 105069L - 生活在树上

We are given a tree where each node carries a single character, either an opening bracket or a closing bracket. For multiple queries, we are asked to look at the characters along the unique path between two nodes and decide whether that resulting sequence satisfies a special…

codeforcescompetitive-programming
CF 105069K - 美丽角对

We are given a set of planar points, and the task is to reason about “beautiful angle pairs” formed by these points.

codeforcescompetitive-programming
CF 105069J - 大兴土木

We are given a line of positions, and on this line there are constraints that forbid certain patterns from being formed inside chosen segments.

codeforcescompetitive-programming
CF 105069I - 大力出奇迹

We are given two rooted trees built on the same set of labeled leaves. The first tree defines a notion of distance between any two leaves through their lowest common ancestor, so any pair of leaves has a fixed distance determined entirely by the structure of that tree.

codeforcescompetitive-programming
CF 105069H - 打饭

We are looking at a planning problem where a person repeatedly performs an action that has a trade-off: each unit of work produces some amount of “food value”, but also consumes some amount of stamina or effort.

codeforcescompetitive-programming
CF 105069F - 乘法与加法

We are given an array of numbers and multiple independent queries. Each query focuses on a subarray defined by a left and right boundary, and a number $k$.

codeforcescompetitive-programming
CF 105069G - 除法与取模

I can’t write a correct editorial for this yet because the actual problem statement content is missing. Right now we only have the title “除法与取模 (Division and Modulo)” and placeholder Input/Output sections, but none of the key details: what is given, what…

codeforcescompetitive-programming
CF 105069E - 不减的数组

We are given an array of integers and the task is to transform it into a non-decreasing sequence by removing elements.

codeforcescompetitive-programming
CF 105069B - rain(hard version)

We are given a set of rainfall events, each event covering a continuous segment of cities on a line. Each event has a value representing how much “rain contribution” we gain if we choose it.

codeforcescompetitive-programming
CF 105069A - rain(easy version)

I can’t reliably write a correct editorial for this problem yet because the actual statement for “rain (easy version)” (Codeforces Gym 105069A) is not present in the prompt you provided, and the accessible attachment content is incomplete and mixed with unrelated…

codeforcescompetitive-programming
CF 105069D - We need more and more OR numbers

The problem revolves around a sequence of numbers that is repeatedly updated using bitwise OR operations, together with online queries that ask for the current value of a particular element after all updates that affect it have been applied.

codeforcescompetitive-programming
CF 105069C - There are many books and books

We are given a sequence of books arranged in a line, where each book has an identifier representing its type. The goal is to perform a minimal number of moves so that the final configuration matches a very restricted structure: the books end up split into two consecutive…

codeforcescompetitive-programming
CF 105085I - The magic sock

The task describes a robot moving on a 2D grid made of different types of cells, where some cells are passable and others are blocked. The robot has a facing direction at all times, and its movement rules distinguish between turning and moving forward.

codeforcescompetitive-programming
CF 105079I - Cupcake Factory

We are working on a grid where each cell describes a different kind of terrain in a factory. Sally starts at the top-left corner and wants to reach the bottom-right corner.

codeforcescompetitive-programming
CF 105079H - Packing Cupcakes

We are simulating a dynamic process on an $N times M$ grid that starts empty and gradually becomes filled cell by cell. Each incoming operation places a cupcake of one of three flavors into a specific empty cell.

codeforcescompetitive-programming
CF 105079G - Sneaking Sprinkles

We are given a row of cupcakes, each starting with some number of sprinkles. Over time, Alice performs a sequence of operations. In each operation she increases every cupcake’s sprinkles by a fixed amount, taken from an array in a fixed order.

codeforcescompetitive-programming
CF 105079F - Cupcake Circle

We are given a circular arrangement of positions indexed from 1 to n, where each position may contain a cupcake with a given “deliciousness” value. Suzie starts at position 1 and repeatedly moves forward by one index at a time, wrapping from n back to 1.

codeforcescompetitive-programming
CF 105079C - Frosting Circles

We are working with a circular “base” region centered at the origin, and several additional circular regions placed on top of it.

codeforcescompetitive-programming
CF 105079A - Ordering Cupcakes

We are given a party with a fixed number of guests, and each guest names exactly one cupcake flavor they would be satisfied with. Each flavor is identified by an integer from 1 to M.

codeforcescompetitive-programming
CF 105079D - Spicy Cupcakes

We are given a sequence of cupcake types, each type having a fixed spiciness value. The judge eats all cupcakes in some order, exactly one of each type.

codeforcescompetitive-programming
CF 105071J - Gacha Rolling

The task is deceptively simple. You are given a single line of input describing a 10-pull action in a gacha game, but the input carries no meaningful constraints or parameters that influence the result.

codeforcescompetitive-programming
CF 105071H - Find the Bug Week 15

The task is about counting how many longest strictly increasing subsequences exist in a given array. A subsequence is formed by deleting elements without changing the order of the remaining ones.

codeforcescompetitive-programming
CF 105071B - Working Out

The statement provides no meaningful input format and no explicit output requirement beyond the problem title. Interpreting this in the way Codeforces sometimes frames puzzle or joke problems, the only consistent reading is that the program is not expected to process any data…

codeforcescompetitive-programming
CF 105071C - Passcode

The task does not involve computation over an input in the usual sense. There is no dataset to transform and no structure to analyze. Instead, the judge is waiting for a single fixed string: Alice’s forgotten five-digit passcode. The interaction rules are simple but strict.

codeforcescompetitive-programming
CF 105071A - Are you a Robot?

You are given several independent test cases. Each test case describes a short string consisting of characters that represent a state or response sequence produced by a system that might or might not be a robot.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 46

Let $x$ be a register containing bits $x_0, x_1, \ldots$, and fix distinct positions $i \neq j$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 45

The error in the previous solution is the implicit claim that one must rely on structural invariance of the relation under permutations.

taocpmathematicsalgorithmsvolume-4medium
CF 105079E - Cupcake Collecting

We are given a square grid of size $N times N$, where each cell is either blocked or usable. A blocked cell is marked with $-1$, and cannot be entered. Every other cell contains a non-negative number representing cupcakes available in that cell.

codeforcescompetitive-programming
CF 105079B - Polkadots

We are given a minimum threshold $n$, and we want to choose a number $x$ representing the number of polkadots on a cupcake. This number must satisfy two constraints at the same time. First, $x ge n$. Second, $x$ must not be a prime number.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 41

Let ordinary generating functions be taken in the sense $A(z)=\sum_{n\ge 0} a_n z^n,$ and extend the functions by $a_0=0$ for $\rho,\lambda,\nu$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 105085F - Follow the LIDAR

We control a small robot moving on an $N times N$ grid, where each cell is either free or blocked. The robot starts in the bottom-left cell, which we can treat as coordinate $(1,1)$, and its goal is to reach the top-right cell $(N,N)$. It always begins facing upward.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 40

Let $\lambda x$ denote the index of the most significant $1$ in $x$, with the convention $\lambda 0 = 0$, so that $2^{\lambda x - 1} \le x < 2^{\lambda x}$ for $x > 0$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 39

Let $x = (x_{w-1}\ldots x_1 x_0)_2$ be a word of fixed width $w$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 38

The error in the previous solution is that it reconstructs a generic “parallel prefix” algorithm and then assigns instruction counts without grounding them in the actual MMIX operations used in proced...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 37

Let (55) and (56) define the function $\lambda x$ recursively in terms of shifts and bit tests, with the standard convention that the recursion terminates at $x = 0$ by assigning a base value $\lambda...

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 36

Let $x = (x_{63}\ldots x_0)_2$.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 35

We address each error by restarting from a correct signed-digit construction and then showing how it is obtained by constant-time bitwise operations.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 34

We work with 2-adic integers and interpret $\rho(x)$ as the 2-adic valuation $v_2(x)$, with $\rho(0)=\infty$.

taocpmathematicsalgorithmsvolume-4math-medium
TAOCP 7.1.3 Exercise 31

The proposed procedure maintains $\rho$ as the number of trailing zero bits of $x$ by repeatedly replacing $x \leftarrow x \gg 1$ while $x \mathbin{&} 1 = 0$.

taocpmathematicsalgorithmsvolume-4medium
CF 105085L - Coworking Spaces

We are given a network of cities connected by bidirectional roads, where each road has a travel time. The key difference from a standard shortest path problem is that only some cities contain Nexters, and we only care about distances between those Nexter cities.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 30

The previous solution fails because it treats the case $\rho = 64$ as requiring a structural change to the algorithm, when in fact the MMIX conventions already make $\rho = 64$ perfectly well-defined...

taocpmathematicsalgorithmsvolume-4medium
CF 105085K - Goddbach conjecture

We are asked to work with a specific infinite sequence derived from primes. We consider odd integers greater than 1 that are not prime. Among these numbers, we keep only those that can be written as the sum of two prime numbers. This filtered increasing list is called $G$.

codeforcescompetitive-programming
CF 105085J - Popping balloons

We maintain a dynamic collection of balloon volumes. Each event either inserts a new value into this collection or asks a query about the current state.

codeforcescompetitive-programming
CF 105085H - Tower Tetris

We are building a structure in a 2D grid where blocks fall from above and form a growing “tower”. Each block is a domino of size 2×1, and it can be placed either horizontally or vertically.

codeforcescompetitive-programming
CF 105085G - The Squared Thinker

We are working with a grid that has exactly two rows and a large number of columns. Every cell starts at zero, and we are allowed to perform a very specific local operation.

codeforcescompetitive-programming
CF 105085D - The three-fountain problem

We are given a square park whose sides are aligned with the axes and span from $(0,0)$ to $(100,100)$. Inside this square, there are three fixed points representing fountains.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 29

Let $\mu_k$ denote Pratt’s magic mask from (47).

taocpmathematicsalgorithmsvolume-4medium
CF 105085E - The supermarket queue

We are given several independent scenarios. In each one, there is a list of customer service times, and the task is to split these customers into two checkout queues.

codeforcescompetitive-programming
CF 105085C - And yet it moves

We are given a tree of galaxies. Each edge of the tree connects two galaxies and comes with two parameters: an initial distance and a yearly growth rate. If an edge connects nodes $u$ and $v$, then after $t$ years the distance on that edge becomes $a + b cdot t$.

codeforcescompetitive-programming
CF 105085B - Farmers Strike

We are given a directed graph of cities and one-way roads. City 0 is the starting point and city $N-1$ is the destination. Each road can be “blocked” by assigning one farmer to it, and blocking removes that directed edge from the graph.

codeforcescompetitive-programming
CF 105085A - Pawn vs King Endgame

We are given a chess endgame on a rectangular board of size $T times T$. Only two pieces matter: a white pawn and a black king. The pawn always moves upward (towards increasing row index), and the king moves one square in any direction, including diagonals.

codeforcescompetitive-programming
CF 105093M - Yet Another Arbitrary Polynomial Problem

We are asked to output a large number of triples of positive integers $(a, b, c)$, each bounded by $10^{18}$, with the additional requirement that every triple must satisfy a fixed cubic polynomial identity in three variables.

codeforcescompetitive-programming
CF 105093L - SwapSwap++++

We are given an initial array and a sequence of swap operations that act on it. Each operation exchanges the values at two positions, and applying the full sequence produces a final arrangement of the array. The twist is that we are not executing the swaps in the given order.

codeforcescompetitive-programming
CF 105093I - Ready Player Juan

We are given a sequence of bosses fought in a fixed order. For each boss, there are two ways to handle the fight.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 28

Let $y = (x + 1) ,&, \bar{x}$.

taocpmathematicsalgorithmsvolume-4medium
CF 105093K - Space Colonizers

We are given a rectangular grid where each cell contains a strength value. One special cell is the starting position of the player, and another is the destination cell containing the Unobtanium mine.

codeforcescompetitive-programming
CF 105093J - Reservoir Doggos

A pack of dogs is fixing a sequence of holes in a damaged reservoir on Titan. Each hole leaks oil at a constant rate until it is fully repaired.

codeforcescompetitive-programming
CF 105093H - Rainbow Energy

We are given several independent test cases. In each one, there is a collection of crystals, each crystal having a color and a radiation value.

codeforcescompetitive-programming
CF 105093F - Meta Sudoku

We are working with a fixed 4 by 4 Sudoku variant. Each cell contains a digit from 1 to 4, and validity means three simultaneous constraints: every row contains no repeated digit, every column contains no repeated digit, and each of the four 2 by 2 blocks also contains no…

codeforcescompetitive-programming
CF 105093E - Minimum Cost Spanning Subgraph

We are given several independent scenarios. In each scenario, there are $n$ countries, and each country has a single integer value representing its technology level.

codeforcescompetitive-programming
CF 105093G - Pandemic

We are given a complete system of players where every unordered pair must eventually interact exactly once. Some interactions have already happened, and we know their order.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 27

Let $A$ be the integer represented by $\alpha$, and let $a$ be the length of $\alpha$ in bits.

taocpmathematicsalgorithmsvolume-4medium
CF 105093D - Look, Up in the Sky!

Working

codeforcescompetitive-programming
CF 105093B - BNA

We are maintaining a string that represents a sequence of nucleotides, where each position holds a single uppercase letter. The string changes over time through two kinds of operations.

codeforcescompetitive-programming
CF 105093C - Deal Breaker

We are given a fixed set of at most 20 possible flaws. Each applicant selects some subset of these flaws and is assigned a desirability score.

codeforcescompetitive-programming
CF 105093A - 4 ♦

We are given a complete record of a single execution of a classic three-switch, three-bulb deduction puzzle. Three switches A, B, and C each control exactly one of the bulbs 1, 2, and 3, but the mapping is unknown. All switches start in the off state.

codeforcescompetitive-programming
CF 1051021 - Доблесть и честь

We are given a group of Spartans, each with a fixed strength called loyalty. We are also given several enemy squads, each with a strength value. A single Spartan squad can be used to defeat one enemy squad if two conditions hold.

codeforcescompetitive-programming
CF 1051025 - Жизнь пешки

We are counting how many different “histories” a white pawn can produce over a fixed number of moves, where only the pawn’s vertical position matters. The pawn always starts on rank 2, and after each move we record its current rank.

codeforcescompetitive-programming
CF 1051024 - Даня и тульские пряники

Each test case gives a rectangular grid of integers, where each cell represents a “tastiness” value, which can be negative or positive.

codeforcescompetitive-programming
CF 1051023 - Перехваченные сообщения

I can’t reliably write a correct editorial yet because the actual problem statement for Codeforces 1051023 - “Перехваченные сообщения” isn’t included in your message, and I don’t have access to fetch it.

codeforcescompetitive-programming
CF 1051016 - Владелец банка

We are given several types of cars, where each type has a fixed number of available units and a fixed price per unit. These types are ordered, and the order matters when prices are equal: earlier types are preferred. Over multiple days, a buyer arrives with two constraints.

codeforcescompetitive-programming
CF 1051015 - Жизнь пешки

We are tracking the vertical movement history of a white pawn that starts on E2 and evolves over a fixed number of white moves. Only the rank matters, so the pawn’s state can be represented by an integer position from 2 to 8.

codeforcescompetitive-programming
CF 1051014 - Даня и тульские пряники

We are given several independent grids. Each grid represents a rectangular cake, where every cell contains an integer value describing its taste contribution.

codeforcescompetitive-programming
CF 1051011 - Доблесть и честь

We are given a set of warriors, each with a strength value we will call loyalty, and a set of enemy groups, each with a required strength. A single group of warriors, called a squad, is used to fight exactly one enemy group.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 22

The error is the use of arithmetic addition in the final recombination step.

taocpmathematicsalgorithmsvolume-4medium
TAOCP 7.1.3 Exercise 219

Let $x\ge 0$ be an integer and define t = x \,\&\, (x+1), \qquad s = t \gg 1, and repeat

taocpmathematicsalgorithmsvolume-4medium