brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104324A - SDU Open

We are asked to assign three types of medals to a fixed number of participants in a contest. Every participant can receive a medal, and medals come in a strict hierarchy: gold is best, then silver, then bronze. The rules do not directly give exact counts.

codeforcescompetitive-programming
CF 104324B - From decreasing to increasing

We are given a permutation of size $n$ that initially appears in strictly decreasing order. The goal is to transform it into increasing order using a very specific operation: we may pick a starting position $s$ and a block length $k$, then swap two adjacent segments of equal…

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 185

Let $f(x_1,\dots,x_n)$ be symmetric, so its value depends only on the Hamming weight w = x_1 + \cdots + x_n.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104324C - Serial Representative

We are given a binary string and a transformation that compresses it into maximal runs of equal characters. Each maximal run is called a “series”, so the string is decomposed into alternating blocks of consecutive zeros and ones.

codeforcescompetitive-programming
CF 104325L - YsaeSort

We are working with an array that changes over time, and we are asked to support two kinds of operations on it. One operation permanently sorts a contiguous segment of the array, physically rearranging the elements in that range.

codeforcescompetitive-programming
CF 104325K - Pirates

We are given a rectangular grid of size $N times M$. Inside this grid, several axis-aligned rectangular regions are marked as bombed. Each bombed region fully covers all cells inside its rectangle, and overlapping rectangles simply reinforce coverage.

codeforcescompetitive-programming
CF 104325J - Pawn Game

We are given a long number line of positions, but only a small subset of those positions actually contains pawns. Each pawn has a position and a color, and no two pawns ever share a position.

codeforcescompetitive-programming
CF 104325I - Palindrome

We are given a string and asked to study all of its substrings through a recursive notion of “palindromic depth.” A substring contributes to the answer only if it is a palindrome. If it is not a palindrome, its contribution is irrelevant and its degree is defined as zero.

codeforcescompetitive-programming
CF 104325D - Flip

We are given a collection of integers, each stored in binary using exactly $K$ bits. We are allowed to perform exactly $P$ operations, and each operation consists of picking one number and flipping one of its bits. Flipping a bit means toggling it from 0 to 1 or from 1 to 0.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 184

Let $P_m$ denote the Boolean predicate that encodes whether a length-$m$ assignment represents a valid permutation of ${1,\dots,m}$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104325G - Monty Hall

We are standing in front of a circular arrangement of $N$ doors. From any door $x$, we are allowed to perform a single type of action: pick a step size $i$ and move exactly $i$ positions forward, wrapping around when we pass door $N$.

codeforcescompetitive-programming
CF 104325H - Nădlac

We maintain a dynamic queue of trucks, where each truck is represented by one of seven ordered colors. The colors form a strict priority chain, from red as the highest priority down to violet as the lowest.

codeforcescompetitive-programming
CF 104325F - IPs

We are managing access to IP addresses, where the entire universe of possible IPs is the integer range from 0 to 10^9. Each country owns a fixed set of IP intervals, and these countries can later be merged into larger groups whose IP sets are unions of the merged members.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 183

Let the odd-indexed variables define a binary fraction A = (0.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104325E - Another Game

We are given a row of $N$ piles arranged from left to right, each containing some positive number of stones. Two players alternate turns, starting with Charlie.

codeforcescompetitive-programming
CF 104325A - Construction plan

We are given a production system where every material is created by exactly one recipe executed on a specific type of machine. Each machine type has a fixed speed multiplier, and each recipe has a base time.

codeforcescompetitive-programming
CF 104325C - Field

Each cell of the grid must be assigned one of two states, which we can think of as planting wheat or planting sunflower. Choosing wheat in a cell gives a fixed profit from matrix A, while choosing sunflower gives a fixed profit from matrix B.

codeforcescompetitive-programming
CF 104325B - DrahSort

We are given an array of non-negative integers, and many queries asking about subarrays. Each query picks a segment $[l, r]$, and we conceptually sort only that segment into non-decreasing order using adjacent swaps.

codeforcescompetitive-programming
CF 104326K - Leapfrog

We are given a line of people, each occupying an integer coordinate on a number line. Each person is labeled from 1 to n, and their label stays attached to them throughout the process, even if their position changes. We are allowed to perform an operation called a leapfrog move.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 182

Let $L_{n,n}(x_1,\ldots,x_n; y_1,\ldots,y_n)$ denote the leading bit of the product of two $n$-bit integers $x=\sum_{i=0}^{n-1} x_{i+1}2^i$ and $y=\sum_{j=0}^{n-1} y_{j+1}2^j$.

taocpmathematicsalgorithmsvolume-4math-project
CF 104326J - Maximal Sum

We are given a multiset of positive integers, each containing at most six decimal digits. From this list we are allowed to pick numbers repeatedly and form a sequence of length up to 108 elements. The score of a chosen sequence is not computed by normal addition.

codeforcescompetitive-programming
CF 104326I - Wrong Sort of Bees

We observe a bee moving in the same plane as Pooh while Pooh travels in a straight line with constant speed. From a fixed external frame, Pooh is simply a point moving linearly.

codeforcescompetitive-programming
CF 104326H - Expotition

We are given a group of people, each identified by a number from 1 to n. Between some pairs of people there are constraints describing how they tolerate each other in a potential expedition group. The constraints come in two forms.

codeforcescompetitive-programming
CF 104326G - Christopher Robin is Learning Object-oriented Programming

We are given a collection of objects where each object has a numeric value and a fixed ordered list of references to other objects. The references form a directed structure, and this structure can include cycles.

codeforcescompetitive-programming
CF 104326F - Repeating b-ary

We are looking at the representation of a fraction, specifically $frac{1}{x}$, but written in base $b$ instead of base 10. When you expand a rational number in any base, its fractional part eventually becomes periodic.

codeforcescompetitive-programming
CF 104326E - Visiting

We are given a directed graph where each house is a node and each existing trackway is a one-way edge. Pooh can only travel along edges in their given direction.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 181

We restart from the correct structural model of the function and rebuild the argument in a way that does not rely on an incorrect “single-bit carry” abstraction.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104326D - Clever Plan

We are given a system with two characters sharing a fixed number of identical honey pots. Initially, the pots are split randomly between them, but only splits where both sides receive at least one pot are allowed.

codeforcescompetitive-programming
CF 104326B - Colored Ring

We are working on a circular board split into $k$ labeled sectors arranged clockwise. Each number from $1$ to $n$ must be placed on a distinct sector, and the final configuration must respect a strict reading order: if you start from the sector containing $1$ and walk…

codeforcescompetitive-programming
CF 104326C - Christopher Robin is Learning Sorting Permutations

We are given a deterministic variant of quicksort where the partition step is written in a very specific way and depends on a pre-chosen sequence of pivot indices produced by repeated calls to a random generator.

codeforcescompetitive-programming
CF 104326A - Forgotten Numbers

I can’t write a correct editorial for Codeforces 104326A without the actual problem statement. Right now your prompt only includes formatting requirements, but the core information (what the input is, what the output means, and what the task is) is missing.

codeforcescompetitive-programming
CF 104328D - John and President

We are given a tree with $n$ vertices, where each vertex represents a person and each person has an integer value $pi$. We also have the notion of a political plan value $x$. A person will support John if and only if their value $pi$ is divisible by $x$.

codeforcescompetitive-programming
CF 104328F - John and Computer Science

We are generating a random string one character at a time, where each character is chosen independently and uniformly from the 26 lowercase English letters. There is a fixed target string of length $n$, and we are watching the stream as it grows.

codeforcescompetitive-programming
CF 104328E - John and Lights

We are given a tree with $N$ nodes. All nodes initially have a light turned on. Then we are given a permutation of the nodes, and in that order, we turn off exactly one node per step.

codeforcescompetitive-programming
CF 104328C - John and Tractor

We are given a grid where every cell behaves like a terrain tile with a movement cost. Some tiles are cheap roads, some are normal dirt, and some are expensive farmland.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 180

We restate the intended theorem in a form that matches the BDD semantics used in Section 7.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104328A - John and Circles

We are given an array of integers, and each query selects a contiguous segment of this array. For every query, we imagine taking that segment and wrapping it into a circle, so after the last element we return to the first.

codeforcescompetitive-programming
CF 104328B - John and AndMax

We are given a directed acyclic graph where every vertex carries a 20-bit integer value. The task is to choose a path that moves along directed edges, uses exactly $k$ vertices, and computes a score defined as the bitwise AND of all values along the path.

codeforcescompetitive-programming
CF 104329E - Yet Another Y Flip

We are given a rooted tree where node 1 is fixed as the root, and each node stores a binary value, either 0 or 1. We are allowed to perform a special operation any number of times.

codeforcescompetitive-programming
CF 104329D - Y Flip

We are given two binary grids of the same size. The goal is to determine whether one grid can be transformed into the other using an unlimited number of specific toggle operations.

codeforcescompetitive-programming
CF 104329A - A Matchsticks Problem

We are given a fixed number of matchsticks and a standard digit display where each digit is formed using a specific number of matchsticks, like a seven-segment display.

codeforcescompetitive-programming
CF 104329B - Yet Another Matchsticks Problem

We are given a supply of identical matchsticks and we want to assemble them into a decimal number. Each digit consumes a fixed number of matchsticks according to a standard seven-segment display configuration.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 18

The flaw in the previous solution is not only that it ignores the structure of the diagram, but that it misidentifies what Algorithm B is actually aggregating over in a binary decision diagram of this...

taocpmathematicsalgorithmsvolume-4simple
CF 104333I - Hail Pythagoras

We are asked to count integer triples $(a, b, c)$ such that $a le b le c$, all values are positive, and they satisfy the Pythagorean relation $a^2 + b^2 = c^2$.

codeforcescompetitive-programming
CF 104333J - Giveaway?

This problem is not really about processing input or computing a value. The task is to output a single fixed string representing the best programming team from Barisal University. There is no meaningful input structure that affects the answer.

codeforcescompetitive-programming
CF 104333H - Maximum Product

We are given an array for each test case and asked to choose three indices in increasing order, then maximize the product of the three corresponding values.

codeforcescompetitive-programming
CF 104333G - Minimum Enclosing Axis-Parallel Square

We are given several independent sets of points on a 2D plane. For each set, we must enclose all points inside an axis-aligned square, meaning the square’s sides are parallel to the coordinate axes.

codeforcescompetitive-programming
CF 104333F - Oh no, Again Query?

We are given an undirected graph where each vertex initially carries a value. Over time, edges are removed, vertex values are updated, and queries ask for the maximum vertex value inside the connected component of a given node.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 179

I can’t write a correct Codeforces 104120F editorial as requested because the problem statement is missing entirely (the “Problem Statement / Input / Output” sections are empty).

taocpmathematicsalgorithmsvolume-4math-research
CF 104333E - A Random Traveller

We are repeatedly picking a city uniformly at random from the set of $n$ cities, and each time we pick a city we pay its associated cost. The process stops only when every city has been seen at least once.

codeforcescompetitive-programming
CF 104333D - Median Sum

We are working with an integer array and we are allowed to pick any subsequence, meaning we can freely choose a subset of indices and keep their values in order, but order itself does not affect the computation since only sums matter.

codeforcescompetitive-programming
CF 104333C - Play With Palindrome

We are given a string of lowercase letters and for every position we want to know how “large a palindrome we can sit inside” while forcing that position to be part of it.

codeforcescompetitive-programming
CF 104333B - Convolution SUM XOR

We are asked to look at all possible ways of pairing two arrays through a permutation, compute a bitwise XOR-based score for each pairing, and then sum those scores over every permutation. Concretely, we have two arrays a and b, both of length n.

codeforcescompetitive-programming
CF 104333A - Convolution XOR SUM

We are given two arrays of equal length. One array represents values attached to indices we are allowed to permute, and the other array represents fixed “slots”.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 178

I can’t write a correct Codeforces 104120F editorial as requested because the problem statement is missing entirely (the “Problem Statement / Input / Output” sections are empty).

taocpmathematicsalgorithmsvolume-4math-medium
CF 104334J - LaLa and Magical Beast Summoning

We are given an array of magical “cells”, each cell described by three numbers that behave like parameters of a structured object.

codeforcescompetitive-programming
CF 104334I - LaLa and Spirit Summoning

We are given a system of points in the plane, where each point is a joint and each connection between two joints is a bar whose length is fixed once chosen. Each bar also has a color, and among bars of the same color we are only allowed to keep at most one.

codeforcescompetitive-programming
CF 104334H - LaLa and Harvesting

We are given a graph whose structure is not arbitrary but built in three layers, each adding constraints that ultimately do not affect the core decision problem. Each vertex has a weight, interpreted as the tastiness of harvesting that vertex.

codeforcescompetitive-programming
CF 104334G - LaLa and Divination Magic

We are given a collection of binary strings, each of length $M$, and each string represents a full assignment of outcomes for $M$ events. In one interpretation, the $j$-th bit being 1 means event $Ej$ is in “salvation”, and 0 means “catastrophe”.

codeforcescompetitive-programming
CF 104334F - LaLa and Monster Hunting (Part 2)

We are given a large undirected simple graph $H$ with up to $10^5$ vertices and edges. Alongside it, there is a fixed “pattern” graph $G$ with 6 vertices (the exact structure is implicit in the statement; what matters is that it is a fixed labeled graph with 6 nodes and a…

codeforcescompetitive-programming
CF 104334E - LaLa and Monster Hunting (Part 1)

We are given a collection of points in the plane, each equipped with a non-negative radius. Each point defines a closed disk.

codeforcescompetitive-programming
CF 104334D - LaLa and Magic Stone

We are given an $N times M$ grid of cells. Each cell is either usable or forbidden. Usable cells must be completely partitioned into identical pieces, where each piece is a fixed polyomino consisting of 7 cells arranged in a U-like shape.

codeforcescompetitive-programming
CF 104334C - LaLa and Lamp

The lamp forms a triangular array of cells. Row i contains i + 1 bulbs, and each bulb is either on or off. The goal is to make every bulb off using a specific operation.

codeforcescompetitive-programming
CF 104334A - LaLa and Magic Circle (LiLi Version)

The task is purely constructive. We are not asked to compute an answer from an input; instead, we must output a complete description of a polygon and a long sequence of operations applied to it.

codeforcescompetitive-programming
CF 104334B - LaLa and Magic Circle (LaLa Version)

We are given a simple polygon described by its vertices in counterclockwise order. The polygon is not necessarily convex.

codeforcescompetitive-programming
CF 104336G - Wall reinforcement

The wall is a sequence of independent segments, each with an initial height. A monster attacks each segment separately using a fixed rule tied to a parameter $k$.

codeforcescompetitive-programming
CF 104336H - Ostovok

We are given a complete graph on $n$ vertices, which means every pair of vertices is connected by an edge. From this dense structure, we are allowed to repeatedly extract spanning trees, with the restriction that once an edge is used in one chosen tree, it cannot be used again…

codeforcescompetitive-programming
CF 104336F - Square between flowers

We are given a grid of size $n times m$, where each cell is colored either black or white. We can imagine the grid as a chessboard-like map of regions. The only allowed way to “draw walls” is along the boundary between two adjacent cells that have different colors.

codeforcescompetitive-programming
CF 104336E - Solve problems every day

We are tracking Maxim’s daily problem solving over a sequence of $n$ days. On each day he solves at least one problem, and we want to assign an exact positive integer to each day. Two quantities are observed at every day $i$.

codeforcescompetitive-programming
CF 104336D - Beautiful Roses

We are given a line of roses, each with an integer height. We are allowed to increase any individual height by 1 any number of times, and each increase costs one unit.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 177

The statement refers to “Theorem A” and to a “quasi-profile,” but neither is defined in the provided section excerpt.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104336A - Number in the Triangle

We are working with Pascal’s triangle, where each row is built from the previous one by adding adjacent pairs, and the edges are always 1. Each row is indexed starting from zero, and within a row, positions are also indexed from zero.

codeforcescompetitive-programming
CF 104336B - GCD of Substrings

We are given a very large integer written as a string, potentially up to one million digits, and we need to compute a value defined in a non-standard way.

codeforcescompetitive-programming
CF 104336C - Two players, two numbers

We are given two players, each starting with an integer written in decimal form. Arthur owns a, Nikita owns b. After that, Arthur appends exactly n decimal digits to the right of his number, and Nikita appends exactly m digits to the right of his number.

codeforcescompetitive-programming
CF 104337M - Different Billing

We are given a contest with a total of $x$ participating teams. Every team belongs to exactly one of three categories, and each category contributes a fixed amount of money to the host. Teams of the first category contribute nothing.

codeforcescompetitive-programming
CF 104337L - Game

We are given a line of points connected by edges. Each edge is colored either white or black, encoded as a binary string where each character describes the color of the edge between consecutive points. So a string of length n represents n+1 points in a row.

codeforcescompetitive-programming
CF 104337K - Dice Game

We are given a game with a fixed number of participants, where one player is distinguished as player 1 and the remaining n players behave symmetrically.

codeforcescompetitive-programming
CF 104337J - Expansion

We are given a line of cells, each with an integer value that can be positive or negative. Applejack starts from the first cell and must eventually cultivate all cells in order from left to right. At the beginning, only cell 1 is cultivated.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 176

Let $h_{a,b}(x)=((ax+b)\gg(n-l)) \bmod 2^l$, with $a\in A={a\mid 0<a<2^n,\ a\ \text{odd}}$ and $b\in B={b\mid 0\le b<2^{n-l}}$.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104337I - Step

We are given several circular rings, each with a fixed length. On every ring there is a marker that starts at position 1. Time is measured in days, and on day k the marker moves forward exactly k steps along its ring.

codeforcescompetitive-programming
CF 104337G - Guess the Polynomial

The hidden object is not an array or a graph but a sparse polynomial defined over a very large finite field. Concretely, the function is a sum of at most 1000 monomials, where each monomial has a coefficient and a power, and all arithmetic is done modulo 998244353.

codeforcescompetitive-programming
CF 104337H - Binary Craziness

We are given an undirected graph with $n$ vertices and $m$ edges. The graph may contain self-loops and multiple edges between the same pair of vertices.

codeforcescompetitive-programming
CF 104337F - Inverse Manacher

We are given a hidden string consisting only of the characters a and b. Instead of seeing the string directly, we are given a transformed version of it together with information about all palindromic radii in that transformed string.

codeforcescompetitive-programming
CF 104337D - Darkness II

We are given a finite set of initially black lattice points on an otherwise infinite integer grid. Time evolves in discrete steps. At each step, any white cell becomes black if at least two of its four orthogonal neighbors are already black.

codeforcescompetitive-programming
CF 104337E - Inverse Counting Path

We are given a target number $x$, and we must construct a grid of size at most $30 times 30$ filled with zeros and ones. A cell marked with one is walkable, while zero blocks movement.

codeforcescompetitive-programming
CF 104337C - Darkness I

We are given an $n times m$ grid where every cell is initially white, except that we are allowed to choose some cells and paint them black at time zero. After that, the grid evolves in discrete steps.

codeforcescompetitive-programming
CF 104337A - Prime Magic

We are given several test cases, each consisting of an integer array. The goal is to transform each array into a non-decreasing sequence using a special type of operation, and we want to do this using as few operations as possible.

codeforcescompetitive-programming
CF 104337B - Mode

We are asked to evaluate a function on every integer in a range and sum the results. For any integer, we look at its decimal representation and count how many times each digit appears. The function value is the largest frequency among all digits.

codeforcescompetitive-programming
CF 104339H - Triangles

We are given a large equilateral triangular grid formed by subdividing a big triangle of side length $n$ into unit equilateral triangles.

codeforcescompetitive-programming
CF 104339G - Card trick

We start with a deck of $n$ distinct cards. A fixed parameter $m$ controls a repeated operation that always behaves the same way on the deck, regardless of the card values. Each operation works in two phases.

codeforcescompetitive-programming
CF 104339F - Corners

We are given an 8×8 board with three possible cell states: a white piece, a black piece, or an empty square. The board is static, and we are not simulating a full game.

codeforcescompetitive-programming
CF 104339E - Compare

We are given two textual representations of real numbers in decimal form and we need to decide which one is larger, or whether they are equal. The twist is that the formatting is very loose.

codeforcescompetitive-programming
CF 104339D - base64 encoding

We are given a stream of bytes, already provided as hexadecimal values, and we need to convert that raw binary data into a Base64-encoded string using the standard alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/.

codeforcescompetitive-programming
CF 104339C - Baguette

We are given a convex quadrilateral $ABCD$ in which all four side lengths and one diagonal $AC$ are known. From this shape, a frame is constructed by cutting material along the boundary, and the required quantity is the total length of baguette needed to form the frame.

codeforcescompetitive-programming
CF 104339B - Four kettlebells

We are given four positive integer weights, and the task is to decide whether it is possible to place all of them on a balance scale so that the system can be perfectly balanced.

codeforcescompetitive-programming
CF 104339A - Three kings

Each king commands an army split into identical regiments. Barley has $a$ regiments, each containing $x$ soldiers, so his total army size is $a cdot x$. Hops and Malt are described the same way, using $b cdot y$ and $c cdot z$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 175

Let a Boolean function on $n$ variables be represented by a reduced ordered BDD in the sense of Section 7.

taocpmathematicsalgorithmsvolume-4math-hard
CF 104343H - Бернард и квадратный колобок

We are given a 3D rectangular block of food with dimensions $Pi, Qi, Ri$. The creature has a rectangular mouth opening of size $H times W$.

codeforcescompetitive-programming
CF 104343G - Бернард и серия пенальти

We are given the partial history of a penalty shootout. Two strings describe the sequence of kicks taken so far: the first string belongs to the first team and the second string belongs to the second team.

codeforcescompetitive-programming
CF 104343E - Бернард и таблица результатов

We are given a tournament involving exactly three teams. The competition consists of N rounds, and in each round the three teams are ranked first, second, and third. The scoring rule is fixed: first place earns 3 points, second place earns 2 points, and third place earns 1 point.

codeforcescompetitive-programming