brain

tamnd's digital brain — notes, problems, research

41650 notes

binary searchconstructive algorithmsgamesgreedyinteractive
*specialconstructive algorithms
*specialprobabilities
chinese remainder theoremmathnumber theory
binary searchgreedytwo pointers
sortings
*specialcombinatoricsmath
implementation
geometry
greedyimplementation
constructive algorithmsdata structures
brute forceimplementationmath
dpgreedysortings
dp
implementation
implementation
constructive algorithmsimplementationstrings
dp
dpgreedy
geometryimplementation
binary searchdata structures
binary searchdptrees
data structuresdpstrings
geometrymath
data structuresgraphsshortest paths
implementationstrings
bitmaskscombinatoricsdpmathnumber theory
brute forcedata structuresmath
dpmathnumber theory
binary searchgraph matchingsgreedy
data structuresdsu
constructive algorithmsgreedyimplementation
greedytwo pointers
binary search
mathnumber theory
chinese remainder theoremcombinatoricsmathnumber theory
brute forcenumber theory
graphs
implementation
implementation
data structuresimplementation
mathnumber theory
brute forcedata structuresgeometrygreedymathsortings
dfs and similargraphsshortest paths
data structuresgamesimplementation
brute forceimplementationnumber theory
greedyimplementation
implementationmath
greedy
fft
data structuresdsuflowsimplementationtwo pointers
constructive algorithmsgreedy
dpstring suffix structuresstrings
CF 896A - Nephren gives a riddle

The construction in this problem generates a sequence of strings where each level wraps the previous one inside a fixed template. The base string, call it $f0$, is a fixed sentence.

codeforcescompetitive-programmingbinary-searchdfs-and-similar
CF 897B - Chtholly's request

We are asked to list special numbers in increasing order and take a prefix sum. A number is considered valid if it reads the same forward and backward in decimal notation and its length is even.

codeforcescompetitive-programmingbrute-force
CF 898F - Restoring the Expression

We are given a single long string consisting only of digits. This string is known to come from a correct arithmetic identity of the form a + b = c, but the symbols + and = were removed and the digits were concatenated.

codeforcescompetitive-programmingbrute-forcehashingmath
CF 898A - Rounding

We are given a single non-negative integer, and we are asked to transform it into a nearby number whose last digit is zero.

codeforcescompetitive-programmingimplementationmath
CF 899F - Letters Removing

We are given a string whose characters are indexed from left to right, and a sequence of operations that repeatedly remove certain characters from specified segments of the current string.

codeforcescompetitive-programmingdata-structuresstrings
CF 899A - Splitting in Teams

We are given several groups of students. Each group has either one student or two students, and these groups are indivisible. The coach wants to form as many teams as possible, where each team must contain exactly three students.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 900B - Position in Fraction

We are given a rational number formed by dividing two integers, and we are interested in its decimal representation after the decimal point. The task is to determine the earliest position where a specific digit appears in that infinite (or terminating) decimal expansion.

codeforcescompetitive-programmingmathnumber-theory
CF 922F - Divisibility

We are asked to build a subset of the numbers from 1 to n such that a very specific quantity computed on this subset equals k exactly. The quantity counts ordered pairs of distinct elements (a, b) where a appears earlier in value than b and a divides b evenly.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedynumber-theory
CF 922A - Cloning Toys

We start with a single original plush toy and no copies. A machine can be applied repeatedly, and each application changes the inventory depending on what type of toy it is applied to.

codeforcescompetitive-programmingimplementation
CF 923F - Public Service

We are given two different trees on the same number of cities. One tree describes bus connections between cities labeled from 1 to N. The other tree describes train connections between cities labeled from N+1 to 2N.

codeforcescompetitive-programmingconstructive-algorithmsgraphstrees
CF 923A - Primal Sport

We are given the value of the game after two moves, call it $X2$. The game starts from some unknown integer $X0 ge 3$, and two players alternately modify this value.

codeforcescompetitive-programmingmathnumber-theory
CF 924C - Riverside Curio

We are given a sequence of observations over consecutive days. Each day corresponds to a water level, and over time Arkady leaves marks at the distinct water levels he has seen so far. If a water level repeats, no new mark is added.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 925B - Resource Distribution

We are given a pool of servers, each with a fixed capacity measured in resource units. Two independent services must be deployed, and each service can use several servers at the same time.

codeforcescompetitive-programmingbinary-searchimplementationsortings
CF 926F - Mobile Communications

We are simulating a bank account over a sequence of days. Each day starts with a fixed charge of $p$ rubles applied to the account. On some specific days, before this charge happens, Arkady deposits money into the account.

codeforcescompetitive-programming
CF 926A - 2-3-numbers

We are asked to count how many integers in a closed interval $[l, r]$ can be written using only the prime factors 2 and 3. Any valid number must have the form $2^x cdot 3^y$, where both exponents are non-negative integers.

codeforcescompetitive-programmingimplementationmath
CF 927A - BuberPool Taxi Optimization

The system simulates a fleet of taxis moving on a large rectangular grid where distance is measured in Manhattan terms, but movement has an additional constraint: whenever a car is instructed to go to a point, it first adjusts its x-coordinate fully and only then adjusts its…

codeforcescompetitive-programming*specialinteractive
CF 928A - Login Verification

We are given a proposed username and a collection of already-registered usernames. The task is to decide whether the new one is “safe” to use, meaning it is not considered equivalent to any existing username under a set of transformation rules.

codeforcescompetitive-programming*specialstrings
CF 929A - Прокат велосипедов

We are given a sequence of positions along a straight line where bike stations are located. The first station coincides with Arkady’s starting point (school), and the last station coincides with his destination (home).

codeforcescompetitive-programming*specialgreedyimplementation
CF 930E - Coins Exhibition

We are given a line of $k$ coins, each independently oriented either “obverse” (call it O) or “reverse” (call it R). A full configuration is simply a binary string of length $k$, but $k$ can be extremely large, so we cannot enumerate configurations.

codeforcescompetitive-programmingdata-structuresdpmath
CF 930C - Teodor is not a liar!

We are given a collection of integer segments on the line from 1 to m. Each segment contributes coverage to every integer point inside it, including endpoints. For every integer position x, we can compute how many segments cover it; call this value cnt(x).

codeforcescompetitive-programmingdata-structuresdp
CF 930A - Peculiar apple-tree

We are given a rooted tree with vertices numbered from 1 to n, where vertex 1 is the root. Every vertex i greater than 1 has exactly one parent p[i], and that parent always has a smaller index, which implicitly guarantees that the structure is a rooted tree without cycles and…

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 931B - World Cup

We are given a single-elimination tournament with $n$ teams labeled from 1 to $n$. The structure of the tournament is fixed and mechanical: in every round, the remaining teams are sorted by their original labels, then paired consecutively, so team 1 plays 2, 3 plays 4, and so on.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 931A - Friends Meeting

Two people stand on a number line at integer coordinates $a$ and $b$. They want to end up at the same integer position, and each of them can move one step left or right any number of times. The twist is that movement cost is not linear.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 932C - Permutation Cycle

We are asked to construct a permutation of the numbers from 1 to N such that every position behaves in a very specific cyclic way.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 932F - Escape Through Leaf

We are working on a rooted tree where each node carries two numerical attributes, one acting like a “multiplier when leaving a node” and the other acting like a “weight when entering a node”.

codeforcescompetitive-programmingdata-structuresdpgeometry
CF 932A - Palindromic Supersequence

We are given a single lowercase string $A$. The task is to construct another string $B$ such that two conditions hold at the same time: $B$ must read the same forward and backward, and the string $A$ must appear inside $B$ as a subsequence, meaning we can delete some…

codeforcescompetitive-programmingconstructive-algorithms
CF 933E - A Preponderant Reunion

We are given a sequence of non-negative integers. The only allowed operation is to pick a pair of adjacent positions where both values are still positive, subtract the smaller value from both, and pay a cost equal to that smaller value.

codeforcescompetitive-programmingconstructive-algorithmsdp
CF 933A - A Twisty Movement

We are given a sequence made only of two values, 1 and 2, arranged in a line. We are allowed to choose a single contiguous segment of this sequence, reverse it, and then we want to measure how long a non-decreasing subsequence becomes after this operation.

codeforcescompetitive-programmingdp
CF 933B - A Determined Cleanup

We are asked to construct a polynomial whose coefficients are non-negative integers strictly less than a given base $k$, such that when this polynomial is divided by $x + k$, the remainder is exactly the constant polynomial $p$.

codeforcescompetitive-programmingmath
CF 934B - A Prosperous Lot

We are asked to construct a positive integer not exceeding $10^{18}$ such that when it is written in base 10, the total number of “loops” formed by its digits is exactly $k$.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 934A - A Compatible Pair

Two players are interacting with two arrays of integers. One player owns an array of length n, the other owns an array of length m. Each number represents a lantern’s brightness, and brightness can be positive, negative, or zero. The interaction is adversarial.

codeforcescompetitive-programmingbrute-forcegames
CF 936C - Lock Puzzle

We are given a string of length $n$, and we are allowed to transform it using a single operation that cuts the string into a suffix and a prefix. The suffix is reversed and moved to the front, and the prefix is appended after it.

codeforcescompetitive-programmingconstructive-algorithmsimplementationstrings
CF 936B - Sleepy Game

We are given a directed graph where each vertex represents a state of a game token. A token starts at a fixed vertex, and two players alternate moving it along outgoing edges. A player loses immediately if they are to move from a vertex that has no outgoing edges.

codeforcescompetitive-programmingdfs-and-similardpgamesgraphs
CF 937B - Vile Grasshoppers

We are given two integers that describe a vertical structure of branches on a tree. The branches are numbered in increasing order, starting from a low level up to some maximum height.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 937A - Olympiad

We are given a list of participant scores, and we need to count how many different ways we can choose a group of participants to receive diplomas under a very specific rule. A valid group is determined by picking a score threshold.

codeforcescompetitive-programmingimplementationsortings
CF 938F - Erasing Substrings

We start with a single string of lowercase letters and repeatedly perform a sequence of destructive operations. In the i-th operation, we are forced to delete a contiguous block whose length is fixed to be $2i - 1$, but we are free to choose where that block lies in the…

codeforcescompetitive-programmingbitmasksdpgreedy
CF 938E - Max History

We are given a multiset of values, where each value is attached to a distinct position. The task is not to process a single ordering of these values, but to consider every possible permutation of indices, treating identical values at different positions as distinct.

codeforcescompetitive-programmingcombinatoricsmath
CF 938A - Word Correction

The task describes a transformation on a string where certain characters are removed according to a local rule involving vowels. We are given a word and repeatedly modify it until no two adjacent vowels remain.

codeforcescompetitive-programmingimplementation
CF 938B - Run For Your Prize

We are given a set of distinct points on a number line representing prizes. Two people start from fixed positions, one from the left side at position 1 and the other far to the right at position 106.

codeforcescompetitive-programmingbrute-forcegreedy
CF 939F - Cutlet

Arkady cooks a cutlet for a total of $2n$ seconds, and the physics is simple: at every moment it is on exactly one side, and whenever he flips it, the side changes instantly.

codeforcescompetitive-programmingdata-structuresdp
CF 939E - Maximize!

We are maintaining a growing collection of positive integers. The collection starts empty, and we process two types of operations: we either insert a new number, or we ask a question about the current collection.

codeforcescompetitive-programmingbinary-searchgreedyternary-searchtwo-pointers
CF 939A - Love Triangle

We are given a directed structure over $n$ nodes, where each node has exactly one outgoing edge. Concretely, plane $i$ points to plane $fi$, meaning it “likes” exactly one other plane. Self-loops are explicitly disallowed, so no node points to itself.

codeforcescompetitive-programminggraphs
CF 939B - Hamster Farm

Dima has a fixed number of hamsters that will be ready for transport, and a collection of box types, each with a different capacity. Every box used must be completely filled, and all chosen boxes must be of a single type because buying mixed types removes a discount.

codeforcescompetitive-programmingimplementation
CF 940A - Points on the line

We are given several points placed on a number line. Each point is just a single integer coordinate. We want to keep a subset of these points such that the spread of the remaining points is controlled, specifically the difference between the largest and smallest kept point…

codeforcescompetitive-programmingbrute-forcegreedysortings