brain

tamnd's digital brain — notes, problems, research

41536 notes

CF 105053C - Clever Cell Choices

We are given a grid where some cells are blocked and the rest are free. A game starts when the first player chooses any free cell and places a stone there.

codeforcescompetitive-programming
CF 105053B - Beating the Record

We are simulating a repeated attempt to clear a sequence of at most four game levels, where each full attempt either succeeds or fails depending on independent probabilistic choices made inside each level.

codeforcescompetitive-programming
CF 105053A - Almost Aligned

Each meteor starts at a known point in the plane and moves in a fixed direction with constant velocity. After time $t ge 0$, meteor $i$ is at $$(xi(t), yi(t)) = (xi + v{x,i} t,; yi + v{y,i} t).

codeforcescompetitive-programming
CF 105055O - Another Trip

The situation is a simple road trip with a mistake in direction. Two distances are relevant: the first is how far the travelers went after taking the wrong direction, and the second is the remaining distance from their starting point to the destination along the correct route.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 60

Let $K$ be the number of cycles in the graph $G = M_1 \cup M_2$, where $M_1$ is a fixed perfect matching on $\{0,1,\dots,2n-1\}$ and $M_2$ is a uniformly random perfect matching.

taocpmathematicsalgorithmsvolume-4hm-hard
CF 105055K - Knock Code

Each uppercase letter must be translated into its position inside the fixed 5 by 5 Knock Code matrix. Every letter is represented by a pair consisting of its row and column. The numbers themselves are encoded as consecutive asterisks, so row 3 becomes and column 5 becomes .

codeforcescompetitive-programming
CF 105055H - Hawarma

We are given an integer parameter $N$ and a rational function $$f(x) = frac{5xN^2}{x^2 + 3xN - 5N^2}.$$ The task is to find all real values $a$ such that plugging $a$ into the function returns the same value, meaning $f(a) = a$.

codeforcescompetitive-programming
CF 105055G - Genie in the Lamp

We are given a string of length $N$ consisting of three kinds of characters: fixed opening parentheses, fixed closing parentheses, and wildcard positions written as ?. Each wildcard can independently be replaced by either ( or ).

codeforcescompetitive-programming
CF 105055E - Email

We are given a string made only of the characters a and b. This string is not arbitrary: it is supposed to be an encoding of a binary password where each 0 was replaced by the block ab and each 1 was replaced by the block aba.

codeforcescompetitive-programming
CF 105055D - Whose Turn Is It?

Two athletes alternate doing fixed-size blocks of repetitions at a gym. Marcel always performs the first block, then Joãozão, then Marcel again, and so on. Each block contains exactly M repetitions.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 59

We restart from the correct structural fact that the previous argument failed to justify: in an Omega network, _switch settings are not independent generators_, but for permutations with a prescribed...

taocpmathematicsalgorithmsvolume-4math-hard
CF 105055C - Traveling Debtor

The problem gives an undirected, unweighted graph of cities connected by roads. Lex starts at city 1 and must reach city N. Some cities are marked as “debt cities”, meaning passing through them is undesirable. A path is evaluated in two stages.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 58

Let $N=2^d$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 105067L - Everyone Loves Threes Magic (Hard Version)

We are given a function that depends on two layers of summation. First, for a fixed interval $[l, r]$, we look only at numbers divisible by 3 inside that interval. For each such number $x$, we count how many digit ‘3’ appear in its decimal representation and sum this count.

codeforcescompetitive-programming
CF 105067J - Arknights Chips

We are repeatedly simulating a farming process that produces two types of items. Each run of the stage independently yields either a sniper chip with probability $p = frac{a}{100}$ or a caster chip with probability $1 - p$.

codeforcescompetitive-programming
CF 105067K - ANDtreew

We are given a tree with nodes labeled from 1 to n. Each query selects a subset of these nodes, and we are allowed to delete any subset of the selected nodes. After deletions, the remaining nodes form a forest.

codeforcescompetitive-programming
CF 105067I - Fire Fighters

We are given a line of fighters, each carrying a power value. A tournament repeatedly takes the first two remaining fighters in the current sequence and makes them fight. The loser is removed, while in the case of a tie both are removed.

codeforcescompetitive-programming
CF 105067H - Gaslighting

We are given a fixed string and then many independent queries, each query selecting a contiguous segment of that string.

codeforcescompetitive-programming
CF 105067G - Mayoi Tree

We are given a tree where every edge is equipped with two directed weights. If we stand at node u, each neighbor v has a positive weight Cu(v).

codeforcescompetitive-programming
CF 105067E - Another Ordering Problem

Each item in the input represents a topping. The topping has a value, and it also carries a single restriction pointing to another topping index. If you decide to include topping i in your final selection, then the topping bi is no longer allowed to appear together with it.

codeforcescompetitive-programming
TAOCP 7.1.3 Exercise 57

We restart from the actual combinatorial structure of $P(2^d)$ as used in TAOCP: a recursive permutation network built from $2 \times 2$ switches arranged in $2d-1$ stages, where each stage consists o...

taocpmathematicsalgorithmsvolume-4medium
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