brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104252E - Empty Squares

We are given a 1×N board and a collection of segment tiles, one of every length from 1 to N. Initially, a single tile of length K has already been placed somewhere on the board, leaving exactly E empty cells to its left.

codeforcescompetitive-programming
CF 104252D - Daily Trips

Bella travels between two fixed locations every day: home and workplace. She makes exactly two bus trips per day, one going from home to work and the other returning from work to home. At each location, she may store some number of umbrellas.

codeforcescompetitive-programming
CF 104252A - Asking for Money

We are given a directed graph with N people, where each person i has exactly two outgoing edges pointing to the people they will ask for money. The process starts when an outsider selects some person in the town and asks them for money.

codeforcescompetitive-programming
CF 104252B - Board Game

We are given a set of points in the plane, each point representing a token with a unique identifier from 1 to T. Then there is a sequence of P turns. On each turn, a player receives every remaining token whose point lies strictly below a given line of the form $y = Ax + B$.

codeforcescompetitive-programming
CF 104252C - City Folding

We start with a paper strip that is conceptually divided into $2^N$ equal segments. Amelia’s home sits at a known segment index $P$. The strip is repeatedly folded $N$ times.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 224

Let $D$ be a DAG in which every non-source vertex has in-degree $1$.

taocpmathematicsalgorithmsvolume-4medium
CF 104254I - From one to six

We are given an array of length up to one hundred thousand, and every element is restricted to a very small domain: only values from 1 to 6 appear. Over this array we must support two kinds of operations on subsegments. One operation rearranges a chosen segment into sorted order.

codeforcescompetitive-programming
CF 104254J - Reload

We are given a long string whose length is exactly nine times some number $n$. This means the string can naturally be seen as a sequence of $n$ consecutive blocks, each block having length 9. We are also given a fixed target word, “BSUIROPEN”.

codeforcescompetitive-programming
CF 104254G - Broken boards

We are given a broken plank whose bottom edge is fixed on the x-axis and whose top edge is described by a polyline with strictly increasing x-coordinates.

codeforcescompetitive-programming
CF 104254H - Road to Student union

We are given a directed structure over numbered nodes from 1 to n. Each node has a value a[i], which is the number of points Egor gains when he visits that node. Egor always starts at node 1, and his goal is to reach node n.

codeforcescompetitive-programming
CF 104254F - Why 42?

We are given a tree whose nodes represent planets. Each planet initially belongs to one of K labeled groups called galaxies. These galaxies are not connected structures by default, they are just color labels on nodes.

codeforcescompetitive-programming
CF 104254D - Exponentiation calculator

We are given a single arithmetic expression written in a very restricted “calculator language”. The expression contains multi-digit positive integers and two unusual binary operations.

codeforcescompetitive-programming
CF 104254E - Cosmo Go

We are working on an $N times N$ grid where each column has a vertical “blocked” prefix. In column $x$, all cells from row $1$ up to row $Ax$ are forbidden. Everything above that prefix is potentially usable space.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 223

Working

taocpmathematicsalgorithmsvolume-4hard
CF 104254C - Function

We are given a recursively defined function that behaves in two different regimes depending on the input value. If the input is larger than a threshold $a$, the function immediately performs a simple linear transformation by subtracting $b-1$.

codeforcescompetitive-programming
CF 104254B - Maximize

We are given two arrays of equal length, and we are allowed to permute only the second array freely. After fixing a pairing between elements of the first array and the permuted second array, we compute the sum of gcd values over all pairs.

codeforcescompetitive-programming
CF 104254A - Galactical exam

We are given multiple independent queries. Each query describes a square multiplication table of size n × n, where both row and column indices range from 1 to n. Each cell contains the product of its row index and column index.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 222

The universe consists of the 130 elementary variables $a_1,b_1,\ldots,z_5$, where $\ell_j$ denotes the event “letter $\ell$ occurs in position $j$ of a five-letter word.

taocpmathematicsalgorithmsvolume-4hard
CF 104255J - Interdimensional Traveler

Each dimension of the system behaves like an independent one-dimensional random walk. The ship starts at position $ai$ in dimension $i$, and while the system is unstable in that dimension (meaning the coordinate is at least 1), it moves one step right with probability $pi$ and…

codeforcescompetitive-programming
CF 104255I - Palindrome tree

We are given a tree where each vertex carries a lowercase character. We are allowed to delete vertices, but after deletions the remaining vertices must still form a connected subgraph, meaning they induce a connected subtree.

codeforcescompetitive-programming
CF 104255G - Borrow checker

Let $Gamma6 = g(0), g(1), dots, g(2^6-1)$ be the 6-bit Gray binary code, where $$g(k) = k oplus lfloor k/2 rfloor.$$ A Gray cycle of length $2^6$ is a cyclic ordering of all $6$-bit strings in which consecutive strings differ in exactly one bit, including the last and first.

codeforcescompetitive-programming
CF 104255H - Birthday

We are given a convex polygon with $n$ vertices. The only allowed operation is drawing a diagonal between two existing vertices. Each diagonal splits one polygonal region into two smaller regions.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 221

Let $F$ denote the family of 5757 SGB words represented on variables $a_1,\dots,z_5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexi...

taocpmathematicsalgorithmsvolume-4math-hard
CF 104255E - Kitten rescue

The grid describes a small world where a cat must reach a kitten while a dog actively tries to intercept it. Each cell is either blocked, empty, or contains one of the three actors: the cat (start), the kitten (goal), and optionally a dog that moves after every cat action.

codeforcescompetitive-programming
CF 104255D - Binary tree

We are given a binary tree with a value stored at every node. The tree structure is fixed: each node already knows its left and right child. What is not fixed is the placement of values. All values are distinct, but they are currently scattered arbitrarily across the nodes.

codeforcescompetitive-programming
CF 104255C - Sum of fractions

Let $Gamma6 = g(0), g(1), dots, g(2^6-1)$ be the 6-bit Gray binary code, where $$g(k) = k oplus lfloor k/2 rfloor.$$ A Gray cycle of length $2^6$ is a cyclic ordering of all $6$-bit strings in which consecutive strings differ in exactly one bit, including the last and first.

codeforcescompetitive-programming
CF 104255B - Two trees

We are given a connected undirected simple graph with up to 100 vertices and up to 200 edges. The task is to assign each edge one of three labels so that the graph can be interpreted as the union of two spanning trees defined over the same vertex set.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 220

Let $F$ denote the family of 5757 SGB words represented on variables $a_1,\dots,z_5$ as in (131), and let the associated ZDD be constructed in the standard ordered way with variables processed in lexi...

taocpmathematicsalgorithmsvolume-4medium
CF 104255A - Stickers for BSUIR Open

We are given a rectangular sheet of paper with dimensions $n times m$. From this sheet, we want to cut out $k$ identical square stickers, where each sticker is a square with side length $x$. The squares must be fully contained in the sheet, and they are not allowed to overlap.

codeforcescompetitive-programming
CF 104257L - League of Letters

We are given a string consisting of only four possible characters: P, D, A, and O. Each character represents a type of warrior standing in a line. We are allowed to choose any contiguous segment of this line, meaning we pick a substring, and call it a “league”.

codeforcescompetitive-programming
CF 104257I - I'm in Iove with Instagram

We are given a poll with two options. Suppose a total of $n$ people have voted, with $L$ choosing the left option and $R = n - L$ choosing the right one.

codeforcescompetitive-programming
CF 104257K - Kakalan's Karma

We are designing a directed “grade system” with k levels, where each level i has exactly one fallback target ai satisfying 1 ≤ ai ≤ i. If a student fails the exam in grade i, they are sent back to grade ai.

codeforcescompetitive-programming
CF 104257J - Jiggle Joggle

We are given a single sequence of integers, and we are allowed to delete elements while keeping the remaining elements in their original order.

codeforcescompetitive-programming
CF 104257F - Frontier Fortress

We are working with a triangle whose side lengths are integers, written as $a le b le c$. From this triangle, two special points are constructed on sides $AB$ and $AC$.

codeforcescompetitive-programming
CF 104257G - Go Go GPA

We are given a sequence of courses that must be taken in a fixed order. Each course has an estimated score and a credit value. The student divides these courses into exactly $K$ consecutive semesters, and each semester must contain at least one course.

codeforcescompetitive-programming
CF 104257H - Hiro's Hero

We are given a sequence of test cases, and each test case provides an integer $n$. For each $n$, we consider the set ${1, 2, dots, n}$. From this set, we form every possible non-empty subset. For each subset, we compute a value defined in a slightly unusual way.

codeforcescompetitive-programming
CF 104257E - Easter Eggs

Two players, Eason and Emil, play a turn-based game involving two independent piles of items. Eason starts with A eggs, Emil starts with B eggs. They alternate turns according to a fixed starting rule: either Eason goes first or Emil goes first depending on a binary flag C.

codeforcescompetitive-programming
CF 104257D - Dom's Discovery

We are given a directed graph where each vertex represents a student and each directed edge represents a one-way friendship claim.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 22

The core issue in the previous solution is that it tried to justify the simplification by claiming a strong structural symmetry of kernel BDDs that was never actually established.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104257B - Bicycle Burglar

We are given a combination lock described as a multi-dial cyclic system. Each dial behaves like a circular wheel: the i-th dial has values from 0 up to ai − 1, and turning it moves one step clockwise or counterclockwise at a fixed time cost.

codeforcescompetitive-programming
CF 104257A - Acceptable Answer

We are given multiple independent queries. Each query contains two integers, and for each pair we are asked to output their arithmetic product. The input size can be large in terms of number of queries, up to one hundred thousand.

codeforcescompetitive-programming
CF 104257C - Clubhouse Celebrity

We are given a directed relationship graph over up to 2021 users. Each user may follow some subset of all users. From this universe, only a subset of size m is present in a chatroom, and the task is to determine whether there exists a “celebrity” inside this subset.

codeforcescompetitive-programming
CF 104261H - Plantery Observations

We are maintaining a growing string that starts empty and is extended over time. Each update operation appends a new substring to the end, and occasionally we are asked a query about the current full string.

codeforcescompetitive-programming
CF 104261E - Gluing Pluto Back Together

We are given a complete weighted graph with up to 12 vertices. Each vertex represents a rock fragment, and the cost matrix tells us how expensive it is to directly glue any two fragments together.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 219

We restart from the definition of the family and apply the ZDD reduction rules exactly as stated in TAOCP §7.

taocpmathematicsalgorithmsvolume-4medium
CF 104261D - Celestial Sky

We are working on a discrete sky represented as integer coordinates in a small grid, specifically points in a 1000 by 1000 space. Two kinds of points are placed on this grid: stars and black holes.

codeforcescompetitive-programming
CF 104261B - Pluto Discovery!

We are given a single integer $n$, and we need to evaluate a specific summation built from division remainders. For every integer $i$ from 1 to $n$, we divide $n$ by $i$ and take the remainder, then add all those remainders together. The task is to compute this total efficiently.

codeforcescompetitive-programming
CF 104261C - Calibration Complications

We are given two arrays of the same length, and we want to transform them so that every element across both arrays becomes equal to a single common value.

codeforcescompetitive-programming
CF 104262J - Rocket Fuel

We are given a system with $n$ engines, each holding a fuel requirement that changes over time. At the beginning, every engine $i$ has an initial fuel requirement $f{1,i}$. After that, there are $m$ events.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 218

We restart from the exact cover formulation, but we now build the BDD/ZDD constructions in a way that does not rely on variable ordering to magically enforce constraints.

taocpmathematicsalgorithmsvolume-4medium
CF 104262I - Wormholes

The world is a directed graph where planets are nodes and wormholes are directed edges with a damage cost. Meryl and Roberto both start at planet 1 and must independently reach planet n.

codeforcescompetitive-programming
CF 104262H - Plantery Observations

We are maintaining a growing sequence of observations, which can be thought of as a string that starts empty and is extended over time. Each update of the first type appends another string to the end of this global sequence.

codeforcescompetitive-programming
CF 104262F - Plutonian Hot Dog Stand

Let $mathcal{S}(f)$ denote the set of all distinct subfunctions of $f(x1,dots,xn)$ obtained by repeated Shannon decomposition with respect to variables $x1,dots,xn$, as represented in the master profile chart.

codeforcescompetitive-programming
CF 104262G - Path to Pluto

We are given a directed weighted graph with (n) planets and exactly (n-1) roads. Each road has a direction and a travel cost. Planet (1) is special because it represents Pluto, and every planet can reach it through some directed path.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 217

Working

taocpmathematicsalgorithmsvolume-4hard
CF 104262E - Gluing Pluto Back Together

We are given a complete weighted graph on $N$ vertices, where each vertex represents a rock. The cost $C{i,j}$ is the price of directly gluing rock $i$ next to rock $j$.

codeforcescompetitive-programming
CF 104262D - Celestial Sky

We are working on a 2D grid where both stars and black holes are placed at integer coordinates in a small bounded space. Stars represent points we want to count, while black holes invalidate nearby stars.

codeforcescompetitive-programming
CF 104262C - Calibration Complications

The five-letter word pairing scheme in Section 7.2.1.1 relies on masking a packed bitstring so that each mask isolates the lower portion of a word consisting of an integral number of fixed-size letter fields.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 216

An 8×8 chessboard is partitioned into 32 dominoes in a perfect covering.

taocpmathematicsalgorithmsvolume-4hard
CF 104264H - Best

The task gives a single integer and asks us to output another integer based on it. There is no further structure such as arrays, graphs, or multiple queries, so the entire problem reduces to understanding how the output depends on this one value.

codeforcescompetitive-programming
CF 104264F - Online

The five-letter word pairing scheme in Section 7.2.1.1 relies on masking a packed bitstring so that each mask isolates the lower portion of a word consisting of an integral number of fixed-size letter fields.

codeforcescompetitive-programming
CF 104264G - Simple

We are given a single integer $n$ in a very small range up to 2023, and we must produce one integer as output. There are no additional structures like arrays or graphs, so the task is entirely about defining a function $f(n)$ that maps each valid input to a single integer.

codeforcescompetitive-programming
CF 104264E - Permutation

We are given a small sequence of integers, and we are asked to compute a single integer answer derived from its internal structure.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 215

A domino tiling of the $8\times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1\times 2$ or $2\times 1$ domino.

taocpmathematicsalgorithmsvolume-4medium
CF 104264D - TheFool

We are given two small integers, row and col, both ranging from 0 to 14, and we must decide whether the point represented by these coordinates is inside a certain region or outside it.

codeforcescompetitive-programming
CF 104264C - Morco

Let $f(x1,x2,x3,x4,x5)$ be a Boolean function and let $B{min}(f)$ denote the minimum, over all variable orderings, of the number of nodes in its reduced ordered binary decision diagram, including the sink nodes $bot$ and $top$.

codeforcescompetitive-programming
CF 104264A - Vowels

We are given a single string consisting only of lowercase English letters. The task is to compute a single integer based on this string, and print it. From the samples, we observe that only certain letters contribute to the answer, while all others contribute nothing.

codeforcescompetitive-programming
CF 104264B - String

I can’t write a correct editorial for that yet because the actual problem statement for “Codeforces 104264B - String” is missing from your prompt.

codeforcescompetitive-programming
CF 104270L - Sub-cycle Graph

We are given a labeled undirected simple graph on $n$ vertices with exactly $m$ edges. The graph is called valid if we can add some additional edges so that the final graph becomes a single simple cycle that visits all $n$ vertices exactly once.

codeforcescompetitive-programming
CF 104270M - Function and Function

We are given a number written in decimal form and a repeated transformation applied to it. The transformation is defined in two layers. First, there is a function that takes a number and replaces it with the sum of a digit-wise score.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 214

Let the chessboard be the standard $8 \times 8$ grid, decomposed into $64$ unit squares.

taocpmathematicsalgorithmsvolume-4medium
CF 104270K - Airdrop

We are given a fixed target height $y0$ and a set of players, each starting at some integer grid point $(xi, yi)$. There is also a hidden parameter $x0$, the x-coordinate of an airdrop position $(x0, y0)$.

codeforcescompetitive-programming
CF 104270J - Books

We are given a sequence of books, each with a fixed price, and a deterministic purchasing process that scans books from left to right. At each book, if the current money is at least the price, the book is bought and the money decreases; otherwise the book is skipped.

codeforcescompetitive-programming
CF 104270I - Soldier Game

We are given an array of soldier powers arranged in a fixed order. The task is to partition this array into contiguous teams, where each team contains either a single element or exactly two adjacent elements.

codeforcescompetitive-programming
CF 104270H - Mirror

We are given a start point and a target point in the plane. At the start, there are multiple identical stones stacked at the start point. The task is to move all stones to the target point, but they must be transported one by one.

codeforcescompetitive-programming
CF 104270G - Repair the Artwork

We are given a line of $n$ cells, each cell being in one of three states. Some cells are already empty, some contain DreamGrid’s own fixed pattern that must never be touched, and some contain BaoBao’s pattern that must be removed.

codeforcescompetitive-programming
CF 104270F - Tournament

We are asked to construct a multi-round tournament schedule among $n$ knights, where each round pairs up all knights into disjoint duels.

codeforcescompetitive-programming
CF 104270D - Magic Multiplication

We are given the length of two unknown positive integers A and B, and a strange string C that is produced by multiplying them under a non-standard operation. The operation does not behave like normal multiplication.

codeforcescompetitive-programming
CF 104270E - Plants vs. Zombies

We are given a line of plants indexed from 1 to n. Each plant i has a fixed position i and a growth rate a[i]. Initially every plant has zero defense value. A robot starts at position 0, which is the “house”.

codeforcescompetitive-programming
CF 104270B - Kawa Exam

We are given an array of length $n$, where each position represents the correct answer to a multiple-choice question. Each question has an assigned correct choice, and BaoBao can pick exactly one choice per question.

codeforcescompetitive-programming
CF 104270C - Flippy Sequence

We are given two binary strings of equal length. Think of them as two rows of switches, each position holding either 0 or 1. We are allowed to perform exactly two operations, and each operation chooses a contiguous segment and flips every bit inside that segment.

codeforcescompetitive-programming
CF 104270A - Sequence and Sequence

We are given two tightly coupled sequences. The first sequence, P, is fully deterministic and grows in a structured way: the value 1 appears twice, 2 appears three times, 3 appears four times, and so on.

codeforcescompetitive-programming
CF 104273F - Устный счет

We are given a long arithmetic expression written in the usual infix form. It consists of non-negative integers combined with addition and multiplication, and an equality to a final integer value.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 213

Let the ZDD represent a family $\mathcal{F}$ of subsets of ${x_1,\dots,x_n}$, ordered by the variable indices, and let each node $k$ be labeled by $V(k)\in{1,\dots,n}$.

taocpmathematicsalgorithmsvolume-4medium
CF 104273E - Быстрый исполнитель

I can’t write a correct editorial for this yet because the problem statement for Codeforces 104273E - “Быстрый исполнитель” is missing from your prompt.

codeforcescompetitive-programming
CF 104273A - Code Plagiarism

We are given two strings built from lowercase letters. Think of the first string as a long tape of characters produced by Bob, and the second string as the shorter string Alice believes should remain after Bob’s modifications.

codeforcescompetitive-programming
CF 104273D - Перекладывание ответственности

The problem statement for Codeforces 104273D (“Перекладывание ответственности”) is not included in your message, so I don’t have enough information to reconstruct the task reliably.

codeforcescompetitive-programming
CF 104273B - SpamGPT-4

Two automated bots are sending messages to each other on a strict schedule. Both bots always send a message at time zero, and then continue sending messages periodically: the first bot sends at times 0, a, 2a, 3a, and so on, while the second sends at times 0, b, 2b, 3b, and so…

codeforcescompetitive-programming
CF 104273C - Есть n стульев...

I can’t reliably write a correct editorial for this yet because the actual problem statement is missing. “104273C - Есть n стульев...

codeforcescompetitive-programming
CF 104274J - Рудольф и математические часы

We are given a regular N-sided polygon that represents the boundary of a clock face. Its center is the origin, one vertex lies on the positive y-axis, and the polygon is oriented in a fixed way.

codeforcescompetitive-programming
CF 104274H - Рудольф и проблема вагонетки

The railway system forms a directed acyclic graph rooted at node 1. Every edge represents a one-way track segment with a number of people on it who would be hit if the train traverses that edge.

codeforcescompetitive-programming
CF 104274I - Рудольф и дни рождения великих

We are given a person’s birth date and an upper bound year. For each query, we need to count how many times this person will celebrate their birthday from the year after their birth up to and including the given end year.

codeforcescompetitive-programming
CF 104274F - Рудольф и игра в наперстки

We are dealing with a hidden binary array of length $N$. Exactly two positions contain a value of 1, and all other positions contain 0. We cannot see the array directly. Instead, we are allowed to ask queries of the form: give me the sum of values in a subsegment $[L, R]$.

codeforcescompetitive-programming
CF 104274G - Рудольф и формирование букета

We are given a row of flowers, each flower having a type represented by an integer. A florist considers a bouquet “valid” only if it corresponds to a contiguous segment of this row and the segment contains exactly K distinct flower types.

codeforcescompetitive-programming
CF 104274E - Рудольф и номера телефонов

We start with a single initial phone number consisting of digits. From this string, a sequence of new phone numbers is generated.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 212

The flaw in the previous solution is that it tried to define ZDD nodes as states indexed by a subset $X \subseteq U$.

taocpmathematicsalgorithmsvolume-4medium
CF 104274B - Рудольф и кубик Рубика

We are given a fully scrambled state of a 2×2×2 Rubik’s cube, encoded not as physical faces but as a flat list of 24 colored stickers. Each color represents one of the six faces in the solved configuration.

codeforcescompetitive-programming
CF 104274C - Рудольф и кубик Рубика (супер хард)

We are given the state of a very small Rubik-like object that is already a 1×1×1 cube, meaning there are exactly six colored faces with no internal structure.

codeforcescompetitive-programming
CF 104274D - Рудольф и НВП

You've hit your limit. Please try again later.

codeforcescompetitive-programming
CF 104274A - Рудольф и аренда

Rudolf spends up to one million days on a foreign planet, and the entire timeline is treated as a single continuous calendar starting from day one. The key complication is that two independent schedules overlap. The first schedule is monthly rent.

codeforcescompetitive-programming