brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1857F - Sum and Product

The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresmath
CF 1857E - Power of Points

We are given several test cases. In each test case, we start with a list of points placed on a number line. For every point we choose one special position s, and we connect s to every point xi by a segment on the integer line.

codeforcescompetitive-programmingmathsortings
CF 1857D - Strong Vertices

We are given two arrays, a and b, both of length n. From these arrays, we are asked to construct a directed graph with n vertices. There is an edge from vertex u to vertex v (for u != v) if the difference a[u] - a[v] is greater than or equal to b[u] - b[v].

codeforcescompetitive-programmingmathsortingstrees
CF 1857C - Assembly via Minimums

The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.

codeforcescompetitive-programminggreedysortings
CF 1857B - Maximum Rounding

We are given a number written as a string of digits, and we are allowed to repeatedly apply a specific rounding operation that changes digits at a chosen position and propagates carry to higher positions in a non-standard way.

codeforcescompetitive-programminggreedyimplementationmath
CF 1857A - Array Coloring

We are given an array of integers and need to decide whether it can be partitioned into two non-empty groups such that the sums of each group have the same parity-both even or both odd. Each group must contain at least one element.

codeforcescompetitive-programminggreedymath
CF 1858B - The Walkway

Petya walks past benches numbered from 1 to n. Some benches contain cookie sellers. Whenever Petya reaches a bench, he eats a cookie if one of three things is true: 1. The bench contains a seller, in which case he immediately buys and eats a cookie. 2. He has never eaten before.

codeforcescompetitive-programmingbrute-forcedpgreedymathnumber-theory
CF 1858D - Trees and Segments

We are given a binary string representing a row of trees, where each position is either an oak or a fir. The quality of a final arrangement depends only on two numbers: the longest consecutive block of zeros and the longest consecutive block of ones.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedytwo-pointers
CF 1858E2 - Rollbacks (Hard Version)

We are asked to maintain a dynamic array while processing four types of queries: append a number, remove the last $k$ numbers, roll back the last change (append or remove), and report the number of distinct numbers in the array. The array is initially empty.

codeforcescompetitive-programmingdata-structuresinteractivetrees
CF 1858E1 - Rollbacks (Easy Version)

We are asked to maintain an array under four types of operations: appending an element, removing the last $k$ elements, rolling back the last change (which could be either an append or a removal), and querying the number of distinct elements currently in the array.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similartrees
CF 1858C - Yet Another Permutation Problem

We are asked to construct permutations of integers from 1 to $n$ in such a way that, when we compute the greatest common divisor (GCD) between consecutive elements (with wrap-around), the number of distinct GCD values is maximized.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1858A - Buttons

Two players alternate turns removing objects from a shared pool. Each object is a “button” with a restriction: some buttons can only be taken by Anna, some only by Katie, and some are flexible and can be taken by either player.

codeforcescompetitive-programminggamesgreedymath
Kvant Math Problem 1551

A closed broken line with six segments is a hexagonal cycle whose six vertices lie on one circle.

kvantmathematicsolympiad
CF 1859E - Maximum Monogonosity

We are given two arrays of length $n$, $a$ and $b$. For any contiguous subarray, or segment, defined by its start $l$ and end $r$, we can compute a "cost" using the formula $ The problem is subtle because segment costs depend on both ends of the segment and both arrays.

codeforcescompetitive-programmingbrute-forcedpmath
CF 1859D - Andrey and Escape from Capygrad

We are asked to model escape paths in a one-dimensional world where Andrey can use portals repeatedly. Each portal is a segment [li, ri] from which Andrey can enter and teleport to another contained segment [ai, bi].

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsugreedysortings
CF 1859F - Teleportation in Byteland

We are given a tree with n cities connected by roads. Each road has a hardness value wi. The travel time along a road depends on the driver’s skill c and is calculated as ceil(wi / c).

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquergraphsshortest-pathstrees
CF 1859C - Another Permutation Problem

We are given a permutation of the numbers from 1 to n. For a permutation p, define $$text{cost}(p)=sum{i=1}^{n} pi cdot i-max{i=1}^{n}(picdot i).$$ The task is to find the largest possible value of this expression among all permutations of length n.

codeforcescompetitive-programmingbrute-forcedpgreedymath
CF 1859B - Olya and Game with Arrays

We are given multiple arrays, each containing at least two positive integers. We are allowed to move at most one number from each array to some other array. After these moves, the “beauty” of the collection is defined as the sum of the smallest element in each array.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1859A - United We Stand

We are given an array of integers, and our goal is to split it into two non-empty arrays, b and c, such that no element in c divides any element in b. Each element must go into exactly one array. If this is impossible, we return -1.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1860E - Fast Travel Text Editor

We are given a string and a cursor that initially sits between two letters. The cursor can move left or right by one position, and it can also "teleport" between any two adjacent letters x and y if there exists another pair x followed by y elsewhere in the string.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsshortest-paths
CF 1860F - Evaluate RBS

We are given $2n$ tuples of the form $(a, b, c)$, where $a$ and $b$ are positive integers and $c$ is a bracket, either '(' or ')'. Exactly half of the tuples are opening brackets and the other half are closing brackets.

codeforcescompetitive-programmingdata-structuresgeometryimplementationmathsortings
CF 1860D - Balanced String

We are given a binary string, and we are allowed to reorder it using swaps between any two positions. The cost of each operation is one swap, and swaps are unrestricted in the sense that we can choose any pair of indices.

codeforcescompetitive-programmingdp
CF 1860A - Not a Substring

We are given a string s consisting only of parentheses, and we need to construct a new string t of length exactly twice that of s, such that t forms a valid bracket sequence and s does not appear anywhere inside t as a contiguous substring.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1860C - Game on Permutation

We are given a permutation and a game played on its positions. The chip starts nowhere. Alice begins by choosing any position and placing the chip there. After that, players alternate moving the chip.

codeforcescompetitive-programmingdata-structuresdpgamesgreedy
CF 1860B - Fancy Coins

We are asked to determine the minimum number of fancy coins Monocarp must use to pay exactly m burles when he has two types of coins: one worth 1 burle and one worth k burles.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1861F - Four Suits

In this problem, we have a card game with multiple players and a dealer. Each card belongs to one of four suits. The dealer has already partially dealt cards to players, and some cards remain in the deck.

codeforcescompetitive-programmingbinary-searchbitmasksflowsgreedy
CF 1861E - Non-Intersecting Subpermutations

We are asked to consider arrays of length n filled with integers from 1 to k. The "cost" of an array is defined as the maximum number of contiguous subarrays of length exactly k where each subarray contains all integers from 1 to k exactly once, and no element participates in…

codeforcescompetitive-programmingcombinatoricsdpimplementationmath
CF 1861D - Sorting By Multiplication

We are given an array of positive integers, and our task is to transform it into a strictly increasing sequence using the fewest operations.

codeforcescompetitive-programmingdpgreedy
CF 1861C - Queries for the Array

We are asked to check whether a given sequence of symbols could have been produced by operations on an array that starts empty.

codeforcescompetitive-programmingdata-structuresdfs-and-similarimplementationstringstrees
CF 1861B - Two Binary Strings

We are given two binary strings of equal length. Both strings always start with a 0 and end with a 1. We are allowed to repeatedly apply an operation that takes a segment inside one string, provided the endpoints of that segment contain the same character, and then forces…

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1861A - Prime Deletion

We start with a fixed multiset of digits from 1 to 9, each appearing exactly once, written in a row. The only operation allowed is deleting digits one by one, with the restriction that we are not allowed to delete when only two digits remain in the current sequence.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1862F - Magic Will Save the World

We are asked to calculate the minimum time Vika, a sorceress, needs to defeat a sequence of monsters. Each monster has a strength, and Vika has two types of magic-water and fire. In one second, she generates fixed amounts of water and fire mana.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedp
CF 1862E - Kolya and Movie Theatre

Kolya wants to visit a movie theatre over n consecutive days, each day showing a new movie. Each movie has a raw entertainment value a[i], but the enjoyment Kolya actually gains is reduced by how long he has waited since his last visit.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1862C - Flower City Fence

We are given a sequence of fence planks, each with a height, already sorted in non-increasing order. Anya wants to know if the fence is symmetrical when viewed as a grid of unit blocks.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationsortings
CF 1863I - Redundant Routes

We are given a tree, so between any two vertices there is exactly one simple path. From this tree we want to choose several distinct vertex-sets, where each chosen set must itself be the vertex set of some simple path that contains at least two vertices.

codeforcescompetitive-programmingconstructive-algorithmsdptrees
CF 1863H - Goldberg Machine 3

We are dealing with a complete rooted binary tree, meaning every non-leaf node has exactly two children. Each leaf has a “hunger value” representing the number of cookies it must ultimately receive. Non-leaf nodes have a selector that decides which child a cookie moves to.

codeforcescompetitive-programmingdptrees
CF 1863G - Swaps

We are given an array where each position points to a value in the same range as indices. You are allowed to repeatedly pick an index i and swap the value stored at position i with the value stored at position a[i].

codeforcescompetitive-programmingcombinatoricsdpgraphsmath
CF 1863F - Divide, XOR, and Conquer

We are given an array of integers and a strange operation that repeatedly reduces the array by splitting it into two non-empty parts, computing the XOR of each part, and discarding the part with the smaller XOR value.

codeforcescompetitive-programmingbitmasksdpmath
CF 1863E - Speedrun

We are given a set of quests, each of which can only be completed at a specific hour within a repeating game day. Some quests depend on others, meaning they cannot be completed until certain prior quests are done.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphsgreedymathsortingstwo-pointers
CF 1863D - Two-Colored Dominoes

We are given an $n times m$ board partially covered with dominoes. Each domino occupies exactly two adjacent cells, either horizontally or vertically. Some cells may remain empty.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1863C - MEX Repetition

We are given an array of distinct integers ranging from 0 up to n, inclusive. The task is to repeatedly update the array in a very specific way: for each element from left to right, replace it with the MEX (minimum excluded value) of the current array.

codeforcescompetitive-programmingimplementationmath
CF 1863A - Channel

A channel has n subscribers. When a new post is published, exactly a subscribers are online, so those a people immediately read the post. After that, we receive a sequence of notifications. A '+' means some subscriber came online, and a '-' means some subscriber went offline.

codeforcescompetitive-programminggreedyimplementation
CF 1863B - Split Sort

We are given a permutation of numbers from 1 to n, and we want to transform it into the identity permutation where each value sits in its matching index position.

codeforcescompetitive-programminggreedymathsortings
CF 1864I - Future Dominators

Let the grid cells be vertices of an $n times n$ grid graph. A final placement of the numbers $1 ldots n^2$ is valid if every vertex except the one containing $1$ has at least one adjacent vertex with a smaller number.

codeforcescompetitive-programminggraphsgreedy
CF 1864G - Magic Square

We start with two square boards of size $n times n$, each containing the numbers $1$ to $n^2$ exactly once. Think of each number as a labeled tile. The initial board is some arrangement of these tiles, and we want to transform it into a target arrangement.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsimplementation
CF 1864H - Asterism Stream

We are asked to compute the expected number of moves to reach or exceed a target integer n starting from x = 1 when in each move you either increment x by 1 or double it, each with probability 1/2.

codeforcescompetitive-programmingdpmathmatrices
CF 1864F - Exotic Queries

We are given an array of integers a of length n. For each query (l, r), we need to zero out every number in a that lies within the range [l, r] using a set of subtraction operations.

codeforcescompetitive-programmingdata-structuresimplementationsortings
CF 1864E - Guess Game

We are given a multiset of integers, and we repeatedly imagine picking two positions independently, forming an ordered pair of values $(a, b)$. Along with $a$ and $b$, both players also learn the bitwise OR $x = a mid b$.

codeforcescompetitive-programmingbitmasksdata-structuresgamesmathprobabilitiessortingsstringstrees
CF 1864C - Divisor Chain

The failure here is not algorithmic at all. The expected logic is correct: the answer is the minimum absolute value in the array. The issue is purely an implementation bug that leads to no output being printed.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmathnumber-theory
CF 1864D - Matrix Cascade

We are given a square grid filled with bits, and the goal is to turn every cell into zero. The only allowed move flips values in a very specific geometric pattern: you pick a cell as a “center”, and it toggles itself and all cells strictly below it that lie within a…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresdpgreedymath
CF 1864A - Increasing and Decreasing

The problem gives us three integers: a starting value x, an ending value y, and a length n. We need to build an array a of length n that starts at x and ends at y, is strictly increasing, and has strictly decreasing consecutive differences.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1864B - Swap and Reverse

We are given a string and two kinds of moves that let us rearrange its characters in a constrained way. One move swaps characters that are two positions apart, and the other reverses a contiguous block of fixed length $k$.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingsstrings
CF 1866M - Mighty Rock Tower

We are asked to compute the expected number of moves to build a tower of height N using identical small rocks, where each placement may trigger a cascading fall of the top rocks. Every time a rock is placed at height x, the topmost rock has a probability Px/100 of falling.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathprobabilities
CF 1866K - Keen Tree Calculation

We are given a weighted tree, so there is exactly one simple path between any two vertices and every edge contributes a distance equal to its weight. The diameter of this tree is the maximum distance between any pair of vertices under these edge weights.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgeometrygraphsimplementationtrees
CF 1866J - Jackets and Packets

We start with a single stack of $N$ jackets. Each jacket has a color, and the order is fixed from top to bottom. There is a second empty stack.

codeforcescompetitive-programmingdp
CF 1866G - Grouped Carriages

Each carriage initially contains some number of passengers. A passenger starting in carriage i may move left or right, but cannot cross more than Di doors.

codeforcescompetitive-programmingbinary-searchdata-structuresdpflowsgreedy
CF 1866I - Imagination Castle

We are given a grid with $N$ rows and $M$ columns. A game piece starts at the top-left cell $(1,1)$. From any cell, the piece can move either to the right within the same row or downward within the same column, but never left or up.

codeforcescompetitive-programmingdpgamestwo-pointers
CF 1866H - Happy Sets

We are given a collection of $N$ sets, each set is formed from integers in the range $1$ to $K$. The sets are unordered internally, but the array of sets is ordered. After we construct these $N$ sets, we are allowed to permute them in any order.

codeforcescompetitive-programmingcombinatorics
CF 1866F - Freak Joker Process

We are maintaining a group of players, each described by two evolving attributes: an offensive value and a defensive value. Over time, both attributes can change independently through updates.

codeforcescompetitive-programmingbinary-searchdata-structuressortings
CF 1866E - Elevators of Tamem

We are managing three elevators inside a tall building. Each elevator sits on a floor and can move up or down, paying a cost proportional to how far it travels.

codeforcescompetitive-programmingdp
CF 1866A - Ambitious Kid

We are given a list of integers, and we can modify any element by repeatedly incrementing or decrementing it by one. Each such unit change costs one operation.

codeforcescompetitive-programmingmath
CF 1866D - Digital Wallet

We are given several rows of numbers, each row representing a sequence of rewards spread across time positions from 1 to M. We will perform exactly M − K + 1 actions, and each action is tied to a sliding window of K consecutive positions that moves from left to right.

codeforcescompetitive-programmingdpgreedy
CF 1866C - Completely Searching for Inversions

We are given a directed acyclic graph where each vertex has an ordered list of outgoing edges. Each edge carries a label, either 0 or 1, and points to another vertex.

codeforcescompetitive-programmingdfs-and-similardpgraphs
CF 1866B - Battling with Numbers

We are given two integers, but instead of being written in decimal form, they are described by their prime factorizations. One number, call it $X$, is fully determined by a list of primes and their exponents. The other number $Y$ is described the same way.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1867E2 - Salyg1n and Array (hard version)

We are given an array of hidden integers and a fixed segment length $k$. We are not allowed to directly inspect the array, but we can ask queries on any contiguous block of exactly $k$ elements.

codeforcescompetitive-programmingconstructive-algorithmsinteractive
CF 1867F - Most Different Tree

We start with a rooted tree $G$ on $n$ vertices, rooted at vertex $1$. For every vertex $v$, we look at the “subtree of $v$” defined as all vertices whose path from the root passes through $v$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargreedyhashing
CF 1867B - XOR Palindromes

We are given a binary string and we are allowed to “modify” it using another binary string of the same length. That second string is not arbitrary in its effect, because it is constrained only by how many ones it contains.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsstrings
CF 1867D - Cyclic Operations

We start with an array a of length n filled with zeros, and we want to transform it into a target array b of the same length.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargraphsgreedyimplementation
CF 1867E1 - Salyg1n and Array (simple version)

We are given a hidden array of length $n$, where each element is an integer. We do not see the array directly. Instead, we are allowed to ask queries on contiguous segments of fixed length $k$.

codeforcescompetitive-programmingconstructive-algorithmsinteractivemath
CF 1867C - Salyg1n and the MEX Game

We are given a sorted set of distinct integers. We do not control this set directly; instead, we interact with an opponent through moves that change it. Each move we either insert a new number into the set or allow Bob to remove a number under a restriction.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgamesgreedyinteractive
CF 1867A - green_gold_dog, array and permutation

We are given an array a of length n. We must construct a permutation b of numbers from 1 to n such that when we subtract element by element, forming ci = ai - bi, the number of distinct values appearing in c is as large as possible.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1868F - LIS?

We are given an array of integers. In one move, we are forced to pick a segment whose sum is as large as possible among all subarrays of the current array, and decrease every element in that segment by one.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1868C - Travel Plan

The mismatch is not coming from MEX computation anymore. The segment MEX logic in the previous version is actually fine for this problem scale.

codeforcescompetitive-programmingcombinatoricsdpimplementationmathtrees
CF 1868E - Min-Sum-Max

We are given an integer array, and we are allowed to split it into several contiguous blocks. Each block has a sum, and we call these block sums a new array. The constraint is not on individual blocks but on every contiguous group of blocks.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1868D - Flower-like Pseudotree

We are given only the degree of each vertex in a graph that is known to be a pseudotree. That means the final graph must be connected and contain exactly one cycle, while having exactly $n$ edges on $n$ vertices.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementationtrees
CF 1868B1 - Candy Party (Easy Version)

We are given an array of integers representing how many candies each person initially holds. The process that follows is a sequence of transfers, where each person will act exactly once as a giver and will choose a single recipient.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgraphsgreedyimplementationmath
CF 1868A - Fill in the Matrix

We are asked to construct an $n times m$ matrix where every row is a permutation of ${0, 1, dots, m-1}$. This already forces a strong structure: each row contains each value exactly once, so the matrix is composed of $n$ rearrangements of the same multiset.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1868B2 - Candy Party (Hard Version)

We are given a group of people at a party, each initially holding some number of candies. Each person can give a certain number of candies to another person exactly once, with the amount being a power of two and not exceeding the candies they currently hold.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedyimplementationmath
CF 1869B - 2D Traveling

We are given several test cases, each describing a complete weighted travel system on a plane. Every city is a point with integer coordinates, and we are allowed to fly directly between any pair of cities.

codeforcescompetitive-programminggeometrymathshortest-pathssortings
CF 1870H - Standard Graph Problem

We are working with a weighted directed graph with n vertices and m edges. Each vertex can be “highlighted” or “normal,” starting with all vertices normal.

codeforcescompetitive-programmingdata-structuresgraphsgreedytrees
CF 1870E - Another MEX Problem

We are given an array of integers, and we are allowed to carve it into several disjoint contiguous segments, leaving some elements unused if we want. For every chosen segment we compute its MEX, which is the smallest non-negative integer missing from that segment.

codeforcescompetitive-programmingbitmasksbrute-forcedpshortest-paths
CF 1870G - MEXanization

We are given an array, and we look at its prefixes one by one. For each prefix, we treat it as a multiset of integers and imagine repeatedly performing a very unusual operation: we pick any non-empty sub-multiset, remove it, compute its MEX, and insert that MEX back.

codeforcescompetitive-programmingdata-structures
CF 1870F - Lazy Numbers

We are asked to consider the numbers from 1 to $n$ expressed in base $k$. Once expressed in base $k$, we sort these representations lexicographically, like strings. After sorting, we number the elements from 1 to $n$.

codeforcescompetitive-programmingbinary-searchmath
CF 1870D - Prefix Purchase

We are given a process that builds an array from left to right using prefix operations. Initially every position is zero.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1870C - Colorful Table

We are given an array a of length n with integers between 1 and k. From a, we define a square table b of size n × n where each cell (i, j) is the minimum of a[i] and a[j]. Each integer in b represents a "color".

codeforcescompetitive-programmingbinary-searchdata-structuresdpimplementationmathtwo-pointers
CF 1870A - MEXanized Array

We are building an array of length $n$ using non-negative integers, with each element capped at $x$. The array is not arbitrary: it must have a fixed MEX equal to $k$, and among all such valid arrays, we want the one with the largest possible sum of elements.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1870B - Friendly Arrays

We are given two arrays, a of length n and b of length m. We are allowed to repeatedly choose any element bj from b and update every element of a as ai = ai The key observations from the input constraints are that n and m can each be up to 200,000 but the sum across all test…

codeforcescompetitive-programmingbitmasksgreedymath
CF 1872G - Replace With Product

We are given a sequence of positive integers and we are allowed to perform exactly one transformation: pick a contiguous segment, compress it into a single number equal to the product of all elements in that segment, and replace the segment with that single value.

codeforcescompetitive-programmingbrute-forcegreedymath
Kvant Math Problem 1523

Let

kvantmathematicsolympiad
CF 1872F - Selling a Menagerie

We are given a set of animals, each with a cost and a "fear" relationship: every animal fears exactly one other animal, and no animal fears itself. When selling an animal, the money earned depends on whether the animal it fears has already been sold.

codeforcescompetitive-programmingdfs-and-similardsugraphsimplementationmath
CF 1872B - The Corridor or There and Back Again

We are standing at room 1 of a one-dimensional corridor and want to go forward to some room k and then return back to room 1. Time increases by exactly one per step, so reaching room x for the first time takes x−1 seconds, and returning follows the same speed.

codeforcescompetitive-programminggreedyimplementation
CF 1872E - Data Structures Fan

We are given a static array of integers, but the array is split dynamically into two groups depending on a binary string. Each position i contributes its value a[i] either to group 0 or group 1 depending on whether s[i] is 0 or 1. The system supports two operations.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdp
CF 1872D - Plus Minus Permutation

We are given a permutation of numbers from 1 to n, and we are allowed to arrange these numbers in any order. Once the arrangement is fixed, we evaluate it using a rule that looks only at certain positions. Two sets of positions matter.

codeforcescompetitive-programmingmath
CF 1872C - Non-coprime Split

We are given multiple independent queries. Each query provides an interval $[l, r]$, and we need to construct two positive integers $a$ and $b$ such that their sum lies somewhere inside this interval and at the same time $a$ and $b$ share a common divisor greater than one.

codeforcescompetitive-programmingmathnumber-theory
CF 1872A - Two Vessels

We are given two containers holding real-valued amounts of water. One starts with a, the other with b. We also have a cup that can transfer at most c units of water in a single operation.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1873G - ABBC or BACB

We are given a string composed only of the letters A and B, and we are allowed to perform two types of operations on adjacent character pairs. In the first operation, an AB pair can be turned into BC to gain a coin. In the second, a BA pair can be turned into CB to gain a coin.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1873H - Mad City

We are asked to determine if one player, Valeriu, can indefinitely avoid being caught by another player, Marcel, in a city modeled as a connected graph with exactly $n$ buildings and $n$ roads. Each building is a node, and each road is an undirected edge connecting two nodes.

codeforcescompetitive-programmingdfs-and-similardsugamesgraphsshortest-pathstrees
CF 1873F - Money Trees

We are given a row of trees, each tree carrying two attributes: a height and a number of fruits. We want to choose a contiguous segment of these trees.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers
CF 1873E - Building an Aquarium

We are given a row of coral columns, each with some initial height. We want to build a water tank over this structure by choosing a uniform target height $h$.

codeforcescompetitive-programmingbinary-searchsortings
CF 1873D - 1D Eraser

We are given a binary string representing a strip of cells, where each position is either black or white. The only operation allowed is choosing any contiguous segment of fixed length $k$ and repainting all cells in that segment to white.

codeforcescompetitive-programminggreedyimplementationtwo-pointers