brain

tamnd's digital brain — notes, problems, research

41549 notes

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
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
TAOCP 7.1.3 Exercise 29

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

taocpmathematicsalgorithmsvolume-4medium
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
TAOCP 7.1.3 Exercise 218

Let $d \ge 3$ be fixed.

taocpmathematicsalgorithmsvolume-4math-hard
TAOCP 7.1.3 Exercise 216

Working

taocpmathematicsalgorithmsvolume-4math-hard
CF 1051013 - Это магия

The magician’s trick reduces the task of identifying a hidden number between 1 and 100 into answering a fixed sequence of seven yes or no questions.

codeforcescompetitive-programming
CF 1051012 - Прямоугольные треугольники

We are given a set of points on the integer coordinate plane, and we need to count how many distinct triples of these points form a right-angled triangle.

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

We are given a collection of car brands, where each brand has a fixed stock count and a fixed price per car. There are no dynamics in pricing or inventory per day other than cars being removed once bought.

codeforcescompetitive-programming
CF 1051022 - Прямоугольные треугольники

We are given a small set of points on the plane, each with integer coordinates, and we need to count how many distinct triples of these points form a right triangle.

codeforcescompetitive-programming
CF 105104K - Kitchen

We start with a collection of existing “deliciousness values” for pig’s trotter rice dishes. These values form an array, and once sorted, we define the instability of the menu as the largest gap between consecutive values in that sorted order.

codeforcescompetitive-programming
CF 105104J - Journey on the Number Line

We are given several test cases. Each test case describes a set of points placed on a line. Every point has a coordinate and an additional value attached to it. We are required to construct a route that starts at point 1, ends at point n, and visits every point exactly once.

codeforcescompetitive-programming
CF 105104I - Intervals

We are given several test cases, each containing a permutation of the numbers from 0 to n − 1. For any contiguous segment of this permutation, we look at the smallest non-negative integer that does not appear inside that segment, which is the mex of the segment.

codeforcescompetitive-programming
CF 105104H - HNOI2010

We are given a collection of intervals, each interval being a segment on the number line defined by two integers $xi le yi$.

codeforcescompetitive-programming
CF 105104G - Grading Papers

We are given a collection of strings indexed from 1 to n. These strings form a fixed ordered book, but they are not truly static because individual characters inside any string can be modified during the process. Alongside these strings, we process a sequence of operations.

codeforcescompetitive-programming
CF 105104F - 4 Rectangles and 1 Square

We are given four axis-aligned rectangles for each test case. Each rectangle can be rotated, meaning we are free to swap its sides.

codeforcescompetitive-programming
CF 105104E - Election

We are given a list of constituencies, each described only by a single integer representing how many votes it contains.

codeforcescompetitive-programming
CF 105104D - $\text{DAY}^{-1}$

We are given a fixed pattern string that is formed by repeating the block "xtu" exactly n times. So the full string p has length 3n and consists of a very rigid periodic structure: every three characters are always x, then t, then u.

codeforcescompetitive-programming
CF 105104B - Bigger, Bigger, Bigger

We start with two numbers, x and y. Each operation allows us to “pump” one of them: if we choose the first operation, x grows multiplicatively by a factor k and y gets a fixed additive boost d. If we choose the second operation, roles are reversed.

codeforcescompetitive-programming
CF 105104A - Average of Intervals

We are given an array of integers for each test case, and we are allowed to select several intervals that do not overlap. Each chosen interval contributes its sum to a global total, and we also count how many intervals we selected.

codeforcescompetitive-programming
CF 105104C - Calculation of Intervals

We are given an array for each test case and we need to count how many subarrays satisfy a specific parity condition: inside the chosen subarray, at least one value appears an odd number of times.

codeforcescompetitive-programming
CF 105109L - Two Pizzas

We are given two circular arrays representing pizzas, each of length $n$. Each position may contain a single topping value or be empty. The key rule is that a topping only contributes to the final score if, after combining the two pizzas, it is the only topping at its position.

codeforcescompetitive-programming
CF 105109K - Sample Heat

We are given a string made of lowercase letters, which we can think of as a row of musical samples laid out on a disk. Any contiguous segment of this string is a candidate “clip”.

codeforcescompetitive-programming
CF 105109J - Record The Record Record

Bob has a collection of numbered records from 1 to n. Over the next n days, he listens to some subset of these records each day. A record is considered new on a given day if Bob has never listened to it on any earlier day.

codeforcescompetitive-programming
CF 105109I - Record Compression

We are given a collection of songs, where each song has two properties: a storage cost measured in bytes, derived from the length of its title, and a reward value. Amber has a digital vinyl with a fixed capacity in bytes.

codeforcescompetitive-programming
CF 105109H - Prefix Tower

We are given an array of numbers and a transformation that repeatedly replaces the array with its prefix product version. One application of the transformation takes an array and turns each position into the product of everything up to that index.

codeforcescompetitive-programming
CF 105109G - Making Records

We are given a directed structure over $n$ labeled positions, where each position $i$ points to exactly one next position $bi$. This defines a functional graph: every node has outdegree 1, so the graph decomposes into directed cycles with trees feeding into those cycles.

codeforcescompetitive-programming
CF 105109F - Lost in the Album Store

The grid represents a store where each cell has a non-negative value. George starts in the bottom-right corner and wants to reach the top-left corner. He can only move one step at a time either upward or leftward, so every valid route is a monotone path on the grid.

codeforcescompetitive-programming
CF 105109E - Is It Vinyl?

We are given ten points in the plane, each supposed to lie on the boundary of a hidden object. The object is guaranteed to be exactly one of two types: either a vinyl record, whose boundary is a circle, or a cassette tape, whose boundary is an axis-aligned rectangle.

codeforcescompetitive-programming
CF 105109D - Counting Records

We are given the first few values of a sequence $f(1), f(2), dots, f(n)$, and the sequence is defined recursively in a way that depends multiplicatively on all previous values.

codeforcescompetitive-programming
CF 105109C - A Noteworthy Debut

We are given an array of song “excitement” values. We need to count how many contiguous segments of this array can be selected such that inside the segment there exists at least one element that is unusually large compared to the rest of the segment.

codeforcescompetitive-programming
CF 105109A - Skipping Songs

We are given an album represented as a fixed sequence of songs in a circular disc player. The disc starts at the first song and always moves forward in order, wrapping back to the beginning after the last song. Noah does not simply listen sequentially.

codeforcescompetitive-programming
CF 105109B - 6th heaven

We are given a set of $n$ distinct disks labeled from $1$ to $n$. The goal is to place all of them on a single line, forming a permutation of these labels.

codeforcescompetitive-programming
CF 105112L - Lateral Damage

We are placed in a hidden 2D grid of size up to 100 by 100. Inside this grid lie at most ten ships, and each ship is always a straight segment of exactly five consecutive cells, either horizontal or vertical. Ships never overlap, but they can touch each other.

codeforcescompetitive-programming
CF 105112J - Jogging Tour

We are given a set of points in the plane, each representing a bakery. We are allowed to build a street system that consists of exactly two infinite families of straight, parallel lines that are perpendicular to each other.

codeforcescompetitive-programming
CF 105112K - Klompendans

We are placed on the top-left tile of an $n times n$ grid and allowed to walk across the grid using two different “knight-like” movement rules.

codeforcescompetitive-programming
CF 105112I - Isolated Island

The island can be seen as a planar drawing of line segments. Each fence is a straight segment, and fences may cross each other, creating a subdivision of the plane into multiple polygonal regions. Each region corresponds to a piece of land owned by one person.

codeforcescompetitive-programming
CF 105112H - Higher Arithmetic

We are given a multiset of integers, and we are allowed to build a single arithmetic expression that uses each integer exactly once. The only operations available are addition and multiplication, and we may freely insert parentheses to control evaluation order.

codeforcescompetitive-programming
CF 105112G - Galaxy Quest

We are given a fixed network of planets in 3D space, where certain pairs of planets are connected by bidirectional space highways. Each highway is a straight segment with a known length determined by Euclidean distance between its endpoints.

codeforcescompetitive-programming
CF 105112F - Fixing Fractions

Two integers are given as strings of digits, forming a numerator and denominator on each side of a fraction equation.

codeforcescompetitive-programming
CF 105112D - Date Picker

We are given a weekly calendar encoded as a 7 by 24 grid. Each row corresponds to a day and each column corresponds to an hour. A cell is either free or blocked. Free means you are available at that day and hour, blocked means you are busy.

codeforcescompetitive-programming
CF 105112E - Exponentiation

We maintain a collection of variables, all starting from the same base value 2023. Two kinds of operations are applied online. One operation replaces one variable by raising it to the power of another variable.

codeforcescompetitive-programming
CF 105112C - Chair Dance

We are simulating a circle of positions numbered from 1 to n, each initially occupied by exactly one player whose label matches the chair number. The system then applies a sequence of global transformations that move every currently alive player at once.

codeforcescompetitive-programming
CF 105112B - Brickwork

We are given a set of brick types, each with a fixed length, and we are allowed to use an unlimited number of bricks of each type. The goal is to construct an infinitely tall wall of fixed width w. Each row is a sequence of bricks whose total length is exactly w.

codeforcescompetitive-programming
CF 105112A - Arranging Adapters

We are given a set of chargers, each with a fixed physical length, and a long power strip that contains a limited number of sockets arranged in a line.

codeforcescompetitive-programming
CF 105114M - Mirinae

Each planet chooses exactly one other planet to “guard”. You can think of this as a directed graph where every node has exactly one outgoing edge, from node i to node A[i]. We want to select a set of planets S to place inside a protective barrier.

codeforcescompetitive-programming
CF 105114L - Lasers

We are given a permutation of columns. A laser starts at each column at the top of a grid and travels downward through a sequence of rows.

codeforcescompetitive-programming
CF 105114J - Journey of the Repetitor

We are given a directed grid where every cell contains exactly one instruction: move one step north, east, south, or west. The grid is not a finite board for movement, instead it is repeated infinitely in all directions, like a wallpaper.

codeforcescompetitive-programming
CF 105114K - Kinda Ok Array Problem

We are given a single integer array and asked to consider every contiguous slice of it. For each slice, we compute the sum of its elements and check whether that sum is even.

codeforcescompetitive-programming
CF 105114I - Infinitely Long Game

We are given an undirected graph with at most 12 vertices. Each edge can be independently oriented in one of three ways: left-to-right, right-to-left, or removed entirely.

codeforcescompetitive-programming
CF 105114H - Hard Array Problem

We are given two integer sequences of the same length. From any contiguous segment of indices, we can compute two values: the sum of the chosen segment in the first array and the sum of the same segment in the second array.

codeforcescompetitive-programming
CF 105114G - Gear Wheels

We are given a sequence of gear wheels arranged in a fixed left-to-right order, where each gear has a number of teeth. A valid chain is a subsequence of these gears, preserving original order, such that every adjacent pair can directly mesh.

codeforcescompetitive-programming
CF 105114F - False Sanctum: Act 2

We are given a string $S$ of length $N$, and we want to extract a special “generator” string from it. This generator, called the key, is defined as the shortest possible substring that can reproduce the entire original string if we repeatedly place copies of it, allowing…

codeforcescompetitive-programming
CF 105114D - Don't be Perfect

We start from a fixed labeled tree on $N le 25$ vertices. This tree is not the object we are modifying freely, it is a mandatory backbone: every valid graph $G$ must contain all tree edges.

codeforcescompetitive-programming
CF 105114E - Economic Inequality

Each bank starts with a fixed amount of money it must distribute, but it cannot give more than $K$ to any single stakeholder. Each stakeholder already has some initial wealth and also has an upper cap on how much total money they are allowed to end up with after all transfers.

codeforcescompetitive-programming
CF 105114A - An Easy Array Problem

We are given a static array and multiple independent range queries. For each query, we look at a segment from index L to index R, with the guarantee that there are at least four elements inside it.

codeforcescompetitive-programming
CF 105114C - Cake Cutting

We are given a circular cake centered at the origin, and each student makes exactly one straight cut. Every cut is a line segment whose endpoints lie on the circumference of the circle, so each cut behaves like a chord.

codeforcescompetitive-programming
CF 105114B - Batch GCD

We are given a list of integers and need to determine whether there exists at least one pair of distinct elements whose greatest common divisor is greater than one.

codeforcescompetitive-programming
CF 105116D - Многочисленные монеты

We are given a chain of coin types where each type is more valuable than the previous one. The exchange rate is multiplicative along the chain: a fixed number of coins of type i can be exchanged for one coin of type i+1.

codeforcescompetitive-programming
CF 105116A - Present Cubinuous

We are given two types of square tiles that must be packed into a fixed-width rectangular box. The box has width $K$ and an unknown length $X$, and all tiles must be placed axis-aligned, without overlap. One type of tile is a $2 times 2$ square, and there are $A$ of them.

codeforcescompetitive-programming
CF 105116C - Змейка и яблоки

We are simulating a snake moving on a fixed n by m grid that always follows a deterministic “snake-like” path: it scans left to right across each row, and when it reaches the end of a row it jumps to the start of the next row, wrapping from the bottom-right back to the…

codeforcescompetitive-programming
CF 105116B - Акция на день рождения

We are asked to decide whether it is possible to choose a mix of two types of bakery items so that two constraints are satisfied at the same time. Vasилиса must buy exactly one item for each of her N guests, so the total number of items is fixed to N.

codeforcescompetitive-programming
CF 105118D - Увеличивающиеся отрезки

We are maintaining a collection of numbered segments on a number line. Each segment starts with a given interval, and all initial segments share the same length, though that fact mainly matters as a structural hint rather than something we explicitly exploit.

codeforcescompetitive-programming
CF 105118A - Произведения

We are given an $n times n$ table that was originally constructed from an unknown sequence $a1, a2, ldots, an$. Every off-diagonal cell contains the product of two elements of this sequence, specifically $B{i,j} = ai cdot aj$ for $i neq j$.

codeforcescompetitive-programming
CF 105118C - Игра с загадочной строкой

We are given a string s that contains lowercase letters and wildcard characters ?, and another string t consisting only of lowercase letters. Before anything else happens, all ? characters in s must be replaced by lowercase letters chosen by us.

codeforcescompetitive-programming
CF 105118B - Таинственный язык

We are given two kinds of words. One group contains short words, all of equal length a, and there are n distinct words of this type. The other group contains long words, all of equal length b, and there are m distinct words of this type, with a < b.

codeforcescompetitive-programming
CF 105122L - Equality

We are given a single line string that is meant to represent an arithmetic equality between two expressions. Each expression can contain decimal digits and the symbols + and -.

codeforcescompetitive-programming
CF 105122K - Game with stones, more difficult version

We are looking at a two-player impartial game played on a single pile of stones. The game starts with $N$ stones, and players alternate turns. On a turn, the current player removes between $1$ and $K$ stones inclusive.

codeforcescompetitive-programming
CF 105122I - Standard geometry problem

We are given a set of points in the plane and asked to reconstruct the boundary of their convex hull in two different levels of detail.

codeforcescompetitive-programming
CF 105122J - Game with stones

We are playing a two-player take-away game with a single pile of stones. Players alternate turns, and on each turn a player removes between 1 and K stones inclusive.

codeforcescompetitive-programming