brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104018D - Невиданная наглость!

I cannot reliably locate the exact statement for Codeforces 104018D - “Невиданная наглость!” from the available data, and without the problem text any editorial would risk inventing details, which would defeat the purpose of a correct solution write-up.

codeforcescompetitive-programming
CF 104018E - Следы на полях

I can’t write a correct editorial yet because the problem statement for Codeforces 104018E - “Следы на полях” is missing from your prompt.

codeforcescompetitive-programming
CF 104018B - Ограбление века

I can write the full editorial in the exact format you want, but I’m missing the actual problem statement for Codeforces 104018B - “Ограбление века”.

codeforcescompetitive-programming
CF 104018C - Найти ладью

I don’t have the actual statement of Codeforces 104018C “Найти ладью” in your prompt, and without it I’d have to guess the rules of the problem, which would make the editorial unreliable.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 69

Algorithm S constructs new BDD nodes during recursive or memoized evaluation of an operation such as apply, using a shared node pool indexed upward from `TBOT` and downward from `NTOP`, with failure o...

taocpmathematicsalgorithmsvolume-4medium
CF 104020J - Jagged Skyline

A domino tiling of the $8times 8$ board assigns to each unit square a partner square so that every square belongs to exactly one $1times 2$ or $2times 1$ domino. The additional tatami condition forbids any grid vertex where four different dominoes meet.

codeforcescompetitive-programming
CF 104020K - Kiosk Construction

We are given a rectangular grid where every cell contains a unique label from 1 to $h cdot w$. Think of the grid as a directed navigation system: from any current cell, a visitor does not move randomly or along shortest paths, but instead follows a deterministic rule that…

codeforcescompetitive-programming
CF 104020L - Lowest Latency

Codeforces 104020L: Lowest Latency

codeforcescompetitive-programming
CF 104020I - Imperfect Imperial Units

We are given a collection of conversion rules between abstract measurement units. Each rule states that one unit is equivalent to a scaled amount of another unit.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 68

Step S10 of Algorithm S is entered when a newly constructed or retrieved node $t$ has a negative pointer in its LEFT field, indicating that the node represents a terminal value rather than an internal...

taocpmathematicsalgorithmsvolume-4medium
CF 104020H - House Numbering

We are given a connected undirected graph with $n$ intersections. Each edge represents a street between two intersections $u$ and $v$, and each street contains a linear chain of houses.

codeforcescompetitive-programming
CF 104020G - Grinding Gravel

We are given several gravel stones, each with a positive integer weight. We also have a grid made of identical cells, and each cell must be filled exactly to a fixed capacity $k$.

codeforcescompetitive-programming
CF 104020F - Failing Flagship

We are given two wind directions written as strings, and each string represents a direction on a circular compass where directions are refined recursively from coarse to fine.

codeforcescompetitive-programming
CF 104020E - Equalising Audio

We are given a sequence of audio amplitudes. Each amplitude contributes to a notion of “perceived loudness” defined by the square of its value. The system measures average perceived loudness as the mean of these squared values over all positions.

codeforcescompetitive-programming
CF 104020B - Bellevue

We are given a polyline describing the cross section of an island from west to east. The endpoints lie at sea level and every interior point is strictly above sea level.

codeforcescompetitive-programming
CF 104020D - Dividing DNA

We are given a binary interface to a hidden database of DNA strings. The only thing we can do is query whether a chosen substring of our query string appears somewhere in that database.

codeforcescompetitive-programming
CF 104020C - Crashing Competition Computer

We are trying to complete typing a fixed-length program consisting of c characters. Each character takes exactly one unit of time to type. The complication is that after every character is typed, the machine may crash with probability p.

codeforcescompetitive-programming
CF 104020A - Adjusted Average

We are given a list of numeric measurements, and we are allowed to discard at most a small number of them. After discarding, we compute the average of the remaining values. The goal is to make this resulting average as close as possible to a fixed target value.

codeforcescompetitive-programming
CF 104021N - Fibonacci Sequence

The task is extremely direct: we are asked to generate the beginning of a well-known integer sequence defined purely by recurrence. The sequence starts with two fixed seeds, both equal to one, and every later value is obtained by summing the previous two values.

codeforcescompetitive-programming
CF 104021J - Toad's Travel

We are given a connected undirected weighted graph with a strong structural restriction: every edge belongs to at most one simple cycle. This makes the graph essentially a tree with a collection of disjoint cycles attached, i.e. a cactus graph.

codeforcescompetitive-programming
CF 104021L - Xian Xiang

We are given a small grid, up to 7 by 7, where some cells contain “objects” and others are empty. Each object is described by a short string of length at most 5, and each position in the string represents an attribute.

codeforcescompetitive-programming
CF 104021M - Crazy Cake

We place $n$ identical points evenly around a circle, and we are allowed to draw straight chords between any two of these points. The only restriction is geometric: no two chords are allowed to cross in their interiors.

codeforcescompetitive-programming
CF 104021K - Largest Common Submatrix

We are given two square grids of size $n times m$, each cell containing a unique integer within that grid. Values inside a single matrix never repeat, but across the two matrices, values may appear in both.

codeforcescompetitive-programming
CF 104021I - Base62

We are given a number written in an arbitrary positional numeral system with base $x$, where digits are not limited to 0-9 but extend through uppercase and lowercase letters up to a total of 62 distinct symbols.

codeforcescompetitive-programming
CF 104021G - Pot!!

We are given an array of length up to one hundred thousand. Every element starts as 1, and then we perform a sequence of operations that either multiply a contiguous segment by a small integer between 2 and 10, or ask for a query over a segment.

codeforcescompetitive-programming
CF 104021H - Delivery Route

We are given a directed weighted graph with some bidirectional roads and some one-way roads. Each road has a cost, which can even be negative for some directed roads due to special infrastructure.

codeforcescompetitive-programming
CF 104021D - Easy Problem

We are asked to sum a weight over many sequences. Each sequence has fixed length n, and every element lies between 1 and m. We only consider sequences whose greatest common divisor is exactly d. For each valid sequence (a1, a2, ...

codeforcescompetitive-programming
CF 104021F - Function!

We are given a function family that is essentially linear scaling. For each parameter $a0$, the function maps a real number $x$ to $a cdot x$, and its inverse simply divides by $a$.

codeforcescompetitive-programming
CF 104021E - XOR Tree

We are working with a rooted tree where every node stores an integer value. For any node $x$, we look at a restricted region of the tree: all descendants of $x$ whose depth from $x$ is at most $k$. From these nodes we collect their values into a multiset $p(x, k)$.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 67

Algorithm S evaluates a binary Boolean operation \(f \circ g\) on functions represented by reduced ordered binary decision diagrams (BDDs).

taocpmathematicsalgorithmsvolume-4medium
CF 104021C - Image Processing

We are given a sequence of images processed one by one from left to right. Each image has a hidden “true” contrast value, but what we are directly given is an encoded sequence.

codeforcescompetitive-programming
CF 104021A - Girls Band Party

We are given multiple independent scenarios. In each scenario we own a collection of cards, where every card has a name, a color, and a power value.

codeforcescompetitive-programming
CF 104021B - So Easy

We are given an initially zero matrix of size $n times n$. A sequence of operations has been applied where each operation chooses either a full row or a full column and adds a positive integer to every cell in that row or column.

codeforcescompetitive-programming
CF 104022L - Sheep Village

We are given a connected undirected graph with n cities and m roads. Each road has a traversal cost, and the graph is almost a tree: there are at most n edges beyond a spanning tree, and every edge participates in at most one simple cycle.

codeforcescompetitive-programming
CF 104022M - Tower of the Sorcerer

We are given a sequence of monsters, each described by a pair of values: its attack strength and its health. We control a warrior who starts with some initial strength and effectively unlimited health, so survival is not about dying, but about minimizing how much damage the…

codeforcescompetitive-programming
CF 104022K - Browser Games

We are given a stream of URLs, one per day, and after each day we must decide how many “confirmation prefixes” the server must maintain. A confirmation prefix is a non-empty string. A URL is considered valid (i.e.

codeforcescompetitive-programming
CF 104022H - Absolute Space

We are asked to construct a finite set of points in three-dimensional space such that each point has exactly $n$ other points at Euclidean distance exactly 1.

codeforcescompetitive-programming
CF 104022J - Let's Play Jigsaw Puzzles!

We are given a complete set of square jigsaw pieces arranged in an unknown m by m grid. Each piece is identified by a unique number from 1 to m², and for each piece we are given four pointers indicating which other piece lies directly to its north, south, west, and east.

codeforcescompetitive-programming
CF 104022I - The Answer!

We are given two indices $x$ and $y$, an integer base $a$, and a modulus $m$. From these values we construct two Fibonacci-indexed exponents and build two numbers: $$u = a^{Fx} - 1,quad v = a^{Fy} - 1$$ where $Fn$ is the Fibonacci sequence.

codeforcescompetitive-programming
CF 104022G - Photograph

We are given a fixed set of students, each with a unique index from 1 to n and an associated height. A photo is always taken in a strict ordering by student index, not by arrival order.

codeforcescompetitive-programming
CF 104022F - Maximize the Ratio

We are given several test cases, each containing a set of planar points. From these points we are allowed to select some subset and connect them with straight segments so that the segments form the boundary of a convex polygon.

codeforcescompetitive-programming
CF 104022A - Best Player

Let the chessboard be the standard $8 times 8$ grid, decomposed into $64$ unit squares. A domino covering is a perfect tiling by $1 times 2$ or $2 times 1$ rectangles aligned with the grid. Each domino occupies exactly two adjacent squares.

codeforcescompetitive-programming
CF 104022E - Isomerism

We are given four substituents attached to a fixed ethylene-like structure. Think of a double bond between two carbons, where each carbon has two attachments: the left carbon has R1 and R2, and the right carbon has R3 and R4.

codeforcescompetitive-programming
CF 104022D - Farm

We are given a collection of candidate roads between farms. Each road connects two farms and has an associated cost.

codeforcescompetitive-programming
CF 104022C - Lucky Sequence

We are given a sequence of length $n$. Each position holds a non-negative integer, but the allowed range of values is extremely small: the upper bound is a fixed constant derived from an expression involving $sqrt{5}$, which evaluates to a value between 1 and 2.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 66

Let $S=s_0s_1\ldots s_{n-1}$ be the given $n$-bit string.

taocpmathematicsalgorithmsvolume-4medium
CF 104022B - The Great Wall

We are given a sequence of tower heights arranged from west to east. The task is to split this sequence into exactly $k$ contiguous groups, where each group must contain at least one tower.

codeforcescompetitive-programming
CF 104023J - Eat, Sleep, Repeat

We are given a multiset of integers $a1, a2, dots, an$. Each move consists of choosing one element and decreasing it by $1$. Over time, elements drift downward until they eventually become $0$.

codeforcescompetitive-programming
CF 104023M - String Master

We are given a very large infinite binary string built by concatenating binary representations of all non-negative integers in order. It starts as 0, then 1, then 10, 11, 100, 101, and so on, forming a single endless sequence of bits.

codeforcescompetitive-programming
CF 104023K - I Wanna Maker

We are asked to count how many integer intervals $[l, r]$ with $1 le l le r$ satisfy a list of conditions. Each condition talks about whether it is possible to pick $k$ distinct integers inside the interval whose sum equals a target value $x$.

codeforcescompetitive-programming
CF 104023L - Novice Magician

We are given an array of length $2^n$, initially all zeros, and a target array $b$. The only allowed operation is unusual: in one move we pick exactly $2^{n-1}$ distinct positions and assign them values that form an arithmetic progression with step 2.

codeforcescompetitive-programming
CF 104023H - Party Animals

We are given a line of players, each holding one of three possible gestures. The system evolves through two kinds of actions. The first action selects a segment of consecutive players and runs a left to right sequence of matches along the edges inside that segment.

codeforcescompetitive-programming
CF 104023I - Dragon Bloodline

Each test gives a collection of essence types and a collection of worker dragons split by levels. Every essence type has a required amount, and every completed dragon egg consumes exactly that amount of each essence type. Worker dragons do not contribute equally.

codeforcescompetitive-programming
CF 104023G - Grade 2

We are given a fixed integer $x$, and then many queries, each query describing a segment of integers $[l, r]$. For every integer $k$ in such a segment, we form a value by taking $kx$ and XOR-ing it with $x$, then we check whether this resulting number is coprime with $x$.

codeforcescompetitive-programming
CF 104023F - Mooncake Delivery

We are given a weighted undirected graph where nodes represent planets and edges represent tunnels. Each planet has two attributes: a color and a cost. The cost is the amount of power consumed when Melon first lands on that planet.

codeforcescompetitive-programming
CF 104023D - Sternhalma

We are given a fixed small board of 19 positions, each position carrying a value. These values can be positive or negative and represent the score obtained when a piece sitting on that cell is removed in a specific way.

codeforcescompetitive-programming
CF 104023E - Python Will be Faster than C++

We are given a sequence that represents the runtime of a Python implementation across successive versions. The first $n$ values are known from measurement.

codeforcescompetitive-programming
CF 104023C - Grass

We are given a set of points in the plane, and we need to determine whether we can pick one special point A together with four other distinct points B, C, D, E such that the segments from A to each of these four points behave in a very strict geometric way.

codeforcescompetitive-programming
CF 104023A - Dunai

We are given a history of champion teams in a five-position competitive game. Each past champion team consists of exactly five named players, one per fixed position from 1 to 5.

codeforcescompetitive-programming
CF 104023B - Recruitment

We are given a final sequence of values produced from a process that starts with an expression consisting of n positive integers separated by plus signs. Initially everything is summed.

codeforcescompetitive-programming
CF 104024F - Subsequence

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

codeforcescompetitive-programming
CF 104024E - Diameter

We are given an array of values indexed from 1 to n. From this array, we define a complete weighted graph where every pair of distinct indices u and v is connected by a single edge.

codeforcescompetitive-programming
CF 104024D - Bookworm

We are given a collection of book titles, each title being a lowercase string. One of these titles is chosen as the starting point.

codeforcescompetitive-programming
CF 104024C - Array Brush

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

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 65

Let $f_n(k)$ denote the $k$th bit of the binary de Bruijn cycle of order $n$ produced by Algorithms R and D with $m=2$, indexed cyclically for $0 \le k < 2^n$.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104024A - Saki

We are given the name of a special mahjong hand written as a string, and we must output the exact sequence of tiles that correspond to that named hand.

codeforcescompetitive-programming
CF 104024B - ZYW with his score

We are given two integers that come from two hidden numbers, call them $a$ and $b$. Instead of revealing $a$ and $b$ directly, we are only told their sum $a + b$ and their bitwise AND $a land b$. The task is to recover the bitwise XOR $a oplus b$.

codeforcescompetitive-programming
CF 104025M - Counting in Tree

We are given a rooted tree with nodes labeled from 1 to n, where node 1 is the root. Each node i (for i 1) has a parent, so the structure is fixed and the subtree of any node x is well-defined: it consists of x and all nodes in its descendant set.

codeforcescompetitive-programming
CF 104025J - Stones

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

codeforcescompetitive-programming
CF 104025L - Fake Travelling Salesman Problem

We are given an $n times m$ grid where each cell is a vertex of an unweighted graph, and edges exist between cells that share a side.

codeforcescompetitive-programming
CF 104025K - ZYW with tutors

We are given a square matrix of size $n times n$ containing integers. We are allowed to pick exactly one cell in this matrix and replace its value with any real number we want, but this operation can be performed at most once.

codeforcescompetitive-programming
CF 104025E - Equal

We are given two integers, representing two counters that start at different values. In one move, we are allowed to either increase the first counter by 1 or increase the second counter by 2.

codeforcescompetitive-programming
CF 104025I - String

We are given a single lowercase string, and we look at all of its substrings as objects. From these substrings we want to form a set $S$ with a restriction: no two different chosen substrings are allowed to stand in a suffix relationship.

codeforcescompetitive-programming
CF 104025G - Get off work

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

codeforcescompetitive-programming
CF 104025H - Happiness Index

We are given an array of integers representing the happiness levels of residents along a line. For each test case, we must count how many contiguous subarrays have an average happiness whose floor equals a given integer $k$.

codeforcescompetitive-programming
CF 104025F - ZYW with books

We are given a sequence of books arranged on a shelf from front to back, each with a numeric value representing how frequently it is used. Smaller values mean higher priority, and the goal is to reorder the books so that these values become non-decreasing from front to back.

codeforcescompetitive-programming
CF 104025C - Combination

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

codeforcescompetitive-programming
CF 104025D - ZYW with BIT

We are given a small city modeled as a weighted undirected graph. Each intersection is a node, and each road has a travel time. On top of that, every node has a periodic constraint of length $T$. For each time residue $t in [0, T-1]$, a node is either open or closed.

codeforcescompetitive-programming
CF 104025B - BIT Palindrome

We are working with strings of length $n$, where each position can be one of three characters: $b$, $i$, or $t$. Among all such strings, we want to count those that are called “lucky”.

codeforcescompetitive-programming
CF 104025A - Gifts in box

We start with a rectangular 3D arrangement of unit cubes inside a box whose dimensions are $n times m times h$. Each position $(i, j)$ in an $n times m$ grid describes a vertical stack of cubes with height $A{i,j}$. So initially the structure is a height map over a floor plan.

codeforcescompetitive-programming
CF 104027L - 核酸排队

We are modeling a queue of samples where each group contributes some number of collected items, and there is a periodic maintenance penalty applied after processing every fixed batch of people.

codeforcescompetitive-programming
CF 104027K - 零时困境 II

We are given a setup involving a matrix expression of the form $A^T times A$, where $A$ is some matrix and $A^T$ is its transpose. The key operation described in the problem is swapping rows of $A$, and we are told that this operation does not change the value of $A^T times A$.

codeforcescompetitive-programming
CF 104027J - runaway problem

I can’t write a correct editorial from that input because the actual problem content is missing. Right now I only see: There is no statement, no description of what “runaway” refers to, and no constraints.

codeforcescompetitive-programming
CF 104027H - 还是分糖果

We are given two sequences, call them A and B. Each query gives us two prefixes: A[1..x] and B[1..y]. The task is to decide whether these two prefixes “match in terms of distinct elements” in a symmetric way: every value that appears in the prefix of A must already appear in…

codeforcescompetitive-programming
CF 104027I - jump

I can’t write a correct editorial for “Codeforces 104027I - jump” without the actual problem statement. That code alone isn’t enough to reliably reconstruct the task, and guessing would risk producing a completely wrong solution and explanation.

codeforcescompetitive-programming
CF 104027G - 三角力量

We are given an undirected graph, but unlike the standard simple version, between any two vertices there may be multiple edges. Each pair of vertices can be connected by several parallel edges, and those parallel edges all count as distinct choices when forming structures.

codeforcescompetitive-programming
CF 104027C - 异或

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

codeforcescompetitive-programming
CF 104027F - 落石

The problem models a collection of stone blocks falling vertically onto a one dimensional ground made of columns. Each column starts empty at height zero, and as stones are dropped, they stack upward depending on where they land.

codeforcescompetitive-programming
CF 104027E - 技能加点

The problem describes a character-building style optimization where you distribute a limited number of skill points between two attributes, denoted as E and R.

codeforcescompetitive-programming
CF 104027D - 饱了没红包

We are given a sequence of orders, each with a price, and a collection of discount coupons. Each coupon has a threshold value and a discount value. A coupon can only be applied to an order if the order price is at least as large as the coupon’s threshold.

codeforcescompetitive-programming
CF 104027A - lzd的人生经验

The task is essentially a reading-comprehension style simulation compressed into arithmetic. We are given a description of some process that consumes time, along with a limit in seconds, denoted by $m$.

codeforcescompetitive-programming
CF 104027B - Candies

We are given a collection of candy packs. Each pack contains either 2 candies or 3 candies. The task is to determine whether it is possible to distribute all candies among three people so that each person receives exactly the same total number of candies.

codeforcescompetitive-programming
TAOCP 7.1.4 Exercise 64

Let $B(f)$ denote the number of beads of a Boolean function $f$, equivalently the number of nodes in its reduced ordered BDD.

taocpmathematicsalgorithmsvolume-4math-medium
CF 104030K - Keyboard Queries

We are given a hidden string indexed from 1 to n. We never see the characters directly. Instead, we receive two kinds of information about it. The first type of query tells us that a certain substring is guaranteed to read the same forward and backward.

codeforcescompetitive-programming
CF 104030J - Junk Journey

The problem gives us an infinite grid with a small number of special cells: a starting position for a robot, a target cell called the depot, and up to 50 scooters placed at distinct grid coordinates. The robot moves one step at a time in the four cardinal directions.

codeforcescompetitive-programming
CF 104030G - Graduation Guarantee

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

codeforcescompetitive-programming
CF 104030H - Highest Hill

We are given a long sequence of terrain heights sampled at evenly spaced positions. From this sequence, we want to identify a special kind of “peak” defined by choosing three indices i, j, k with i < j < k such that the height first does not decrease up to j and then does…

codeforcescompetitive-programming
CF 104030I - Icy Itinerary

We are given a town modeled as an undirected graph on n houses. Some pairs of houses are connected by roads, and every other pair is considered connected only by an implicit “non-road” relation, meaning Thomas must travel between them using skis.

codeforcescompetitive-programming
CF 104030E - Enigmatic Enumeration

We are given an undirected simple graph. The task is not to find just one cycle, but to determine how many cycles achieve the minimum possible length among all cycles in the graph.

codeforcescompetitive-programming
CF 104030F - Foreign Football

We are given a hidden set of $n$ strings, one per football team, and every pair of distinct teams produces a recorded match string that is simply the concatenation of the two team names in order.

codeforcescompetitive-programming