brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1881D - Divide and Equalize

We are given several independent test cases. In each test case, we start with an array of positive integers. We are allowed to repeatedly pick two different positions and move a multiplicative factor from one value to the other, but the factor must be a divisor of the first…

codeforcescompetitive-programmingmathnumber-theory
CF 1881A - Don't Try to Count

We start with a string x. One operation replaces x with x + x, meaning the current string is appended to itself and its length doubles. We are also given a target string s.

codeforcescompetitive-programmingbrute-forcestrings
CF 1881C - Perfect Square

We are given an $n times n$ matrix of lowercase letters, where $n$ is even. The goal is to transform the matrix into a "perfect square," which is defined as a matrix that remains unchanged when rotated $90^circ$ clockwise.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1881B - Three Threadlets

We are given three positive integers, each representing the length of a thread. In one move, we pick a single thread and split it into two smaller threads with integer lengths, both strictly positive, and their sum equal to the original length.

codeforcescompetitive-programmingmath
CF 1882C - Card Game

We have a deck of cards, each containing an integer value. During the game we repeatedly remove cards from the current deck. If we remove a card at an odd position, its value is added to our score.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1882E2 - Two Permutations (Hard Version)

We are given two independent permutations, one of length $n$ and another of length $m$. We repeatedly apply a synchronized operation: in each step we choose a position in each array, then rotate each array so that the chosen element becomes the last element, preserving…

codeforcescompetitive-programmingconstructive-algorithms
CF 1882E1 - Two Permutations (Easy Version)

We are given two permutations, one of size $n$ and one of size $m$, which are simply arrays containing all integers from 1 to $n$ and 1 to $m$ in some order. The goal is to transform both permutations into their sorted forms simultaneously, using a specific operation.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedynumber-theory
CF 1882B - Sets and Union

We are given several sets of integers. We can choose any subset of these sets (including none) and take the union of the selected sets. A set is attainable if it can be formed in this way.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsgreedy
CF 1882D - Tree XOR

We have a tree where each vertex contains a number. After choosing a root, we may repeatedly pick a vertex and XOR every value inside its subtree by some non-negative integer c. Applying such a spell costs (subtree size) × c.

codeforcescompetitive-programmingbitmasksdfs-and-similardpgreedytrees
CF 1882A - Increasing Sequence

We need to construct a new sequence $b$ of length $n$. Every element of $b$ must be a positive integer. The sequence must be strictly increasing, and for every position $i$, we are forbidden from choosing $bi = ai$.

codeforcescompetitive-programminggreedy
CF 1883G2 - Dances (Hard Version)

We have two arrays of the same size. Before doing anything else, we may reorder each array arbitrarily. An operation removes one element from the first array and one element from the second array.

codeforcescompetitive-programmingbinary-searchgreedysortingstwo-pointers
CF 1883C - Raspberries

We are given an array and a small integer $k$, where $2 le k le 5$. In one operation we may pick any element and increase it by one. The task is to find the smallest number of operations needed so that the product of all array elements becomes divisible by $k$.

codeforcescompetitive-programmingdpmath
CF 1883F - You Are So Beautiful

We are given an array of integers and are asked to count the number of contiguous subarrays whose elements appear as a subsequence in the original array exactly once.

codeforcescompetitive-programmingdata-structures
CF 1883G1 - Dances (Easy version)

We are given two arrays, a and b, each of size n. We are allowed to remove elements from both arrays in pairs, and before doing so, we can reorder the arrays arbitrarily.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1883D - In Love

We are asked to maintain a dynamic multiset of segments on the number line, processing additions and deletions one by one. After each operation, we must determine whether the multiset contains at least two segments that do not overlap.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1883E - Look Back

We are given an array of integers, and our task is to transform it into a non-decreasing sequence using the minimum number of operations. The operation allowed is doubling a single element any number of times.

codeforcescompetitive-programmingbitmasksgreedy
CF 1883A - Morning

We are asked to enter a four-digit PIN on a device where the digits are arranged in a circle from 0 to 9. The cursor starts at 1. Each second, we can either press the current digit or move the cursor to an adjacent digit.

codeforcescompetitive-programmingmath
CF 1883B - Chemistry

We are asked to determine whether a string can be reduced to a palindrome after removing exactly k characters. The string consists only of lowercase letters, and the number of characters to remove is strictly less than the string length.

codeforcescompetitive-programmingstrings
CF 1884E - Hard Design

We are given an array of integers and the ability to increment a contiguous segment of the array in a single operation. Each operation has a cost measured as the square of the segment's length, and we earn coins equal to this cost.

codeforcescompetitive-programminggreedyimplementationmath
CF 1884D - Counting Rhyme

We are given an array of integers a[1..n], each between 1 and n. We need to count the number of pairs (i, j) with i < j such that there is no k for which both a[i] and a[j] are divisible by a[k].

codeforcescompetitive-programmingdpmathnumber-theory
CF 1884B - Haunted House

We are given a binary number as a string of length $n$, which may contain leading zeroes. The task is to determine, for each integer $i$ from 1 to $n$, the minimum number of adjacent swaps required to make the number divisible by $2^i$, or indicate if it is impossible.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers
CF 1884C - Medium Design

We are given a very long array, initially all zeros, and a collection of segments on this array. Each segment, if chosen, adds one to every position inside its interval. We are allowed to choose any subset of segments.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 1884A - Simple Design

For each test case, we are given a starting number x and an integer k. A number is considered beautiful if the sum of its decimal digits is divisible by k. The task is to find the smallest integer y such that y ≥ x and the digit sum of y is divisible by k.

codeforcescompetitive-programmingbrute-forcegreedymath
Kvant Math Problem 1525

Place the four collinear points on the $x$ axis as

kvantmathematicsolympiad
CF 1885A - Deterministic Scheduling for Extended Reality over 5G and Beyond

This is not a traditional optimization problem where the judge checks whether you found the best answer. The statement describes a very complicated wireless scheduling model involving users, cells, time slots, frequency blocks, power allocation, interference, frame deadlines…

codeforcescompetitive-programming*special
CF 1886F - Diamond Theft

Each camera can be hacked multiple times. A hack performed at second T disables that camera during the interval [T + 1, T + s]. The only moments that matter are the two thefts. Let the first diamond be stolen at time A and the second at time B, with A < B.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1886E - I Wanna be the Team Leader

We are given a set of programmers, each with a stress tolerance level, and a set of projects, each with a difficulty.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedymathsortingstwo-pointers
CF 1886D - Monocarp and the Set

Think about the process in reverse. Instead of starting with an empty set and inserting numbers, start with the full set {1,2,…,n} and repeatedly remove one number until only one number remains.

codeforcescompetitive-programmingcombinatoricsdata-structuresmath
CF 1886A - Sum of Three

We are given an integer $n$ and must split it into three numbers whose sum is exactly $n$. The three numbers must satisfy three conditions simultaneously. They must all be positive, they must all be distinct, and none of them may be divisible by $3$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1886C - Decreasing String

We are given a string and asked to generate a sequence of strings by removing exactly one character at a time to make the resulting string lexicographically minimal.

codeforcescompetitive-programmingimplementationstrings
CF 1886B - Fear of the Dark

Monocarp starts at the origin $(0,0)$ and wants to reach his home at point $P$. The only illuminated regions come from two lanterns located at points $A$ and $B$. Both lanterns must use the same power $w$, which means each lantern illuminates a disk of radius $w$.

codeforcescompetitive-programmingbinary-searchgeometrymath
CF 1887F - Minimum Segments

We are given a sequence of integers r1, r2, ..., rn, called the characteristic of some unknown sequence a1, a2, ..., an of length n.

codeforcescompetitive-programmingconstructive-algorithms
CF 1887E - Good Colorings

We are asked to interact with a grid of size $n times n$. Initially, $2n$ cells are pre-colored with unique colors from $1$ to $2n$, and the rest are uncolored. In each of up to 10 allowed moves, we can request Alice to color a previously uncolored cell.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgraphsinteractive
CF 1887D - Split

We are given an array of distinct integers ranging from 1 to n, and we are asked to answer multiple queries about contiguous subarrays.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdsumathtreestwo-pointers
CF 1887C - Minimum Array

We are given an array of integers and a sequence of operations that increment segments of the array by a given value. Each operation specifies a contiguous subarray and an integer to add.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresgreedyhashingtwo-pointers
CF 1887B - Time Travel

We are given a fixed set of cities and a sequence of historical snapshots. Each snapshot describes which roads exist between cities at that moment in time. These road systems change completely from one snapshot to another.

codeforcescompetitive-programmingbinary-searchgraphsshortest-paths
CF 1889F - Doremy's Average Tree

I can't reliably write a complete correct editorial for CF 1889F from the problem statement alone. This is a 3500-rated problem, and the official editorial page no longer exposes the written explanation.

codeforcescompetitive-programmingdata-structuresdpgreedytrees
CF 1889E - Doremy's Swapping Trees

We are given two trees on the same labeled vertex set. The labels are fixed and unique, so each node identity is global across both trees.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 1889D - Game of Stacks

We are given a collection of $n$ stacks, each containing integers between $1$ and $n$. For each position $i$, we define a function that repeatedly moves to the stack indicated by the top element of the current stack, popping that top element, until it reaches an empty stack.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementationtrees
CF 1889C2 - Doremy's Drying Plan (Hard Version)

We are given a line of cities and a sequence of rainy days. Each day paints a contiguous segment of cities with rain, and a city is considered dry only if none of the days ever cover it. On top of this fixed schedule, we are allowed to “cancel” exactly $k$ of the rainy days.

codeforcescompetitive-programmingdata-structuresdp
CF 1889A - Qingshan Loves Strings 2

We are given a binary string and allowed to modify it by repeatedly inserting the fixed substring 01 at arbitrary positions. Each insertion increases the length by two characters and keeps all existing characters intact, only shifting them.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1889C1 - Doremy's Drying Plan (Easy Version)

We are asked to find how many cities can be made completely dry over a sequence of days, given that on each day a contiguous segment of cities receives rain. Doremy has a special ability: she can cancel the rain on exactly two of these days.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 1889B - Doremy's Connecting Plan

We are given a set of cities, each city having a non-negative weight representing population. Initially, there are no connections between any cities.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1890A - Doremy's Paint 3

We are given several test cases, each consisting of an array of positive integers. The task is not to construct a new array from scratch but to decide whether we can reorder the given elements so that every pair of adjacent elements in the resulting sequence has the same sum.

codeforcescompetitive-programmingconstructive-algorithms
CF 1891F - A Growing Tree

We are asked to process a sequence of operations on a growing rooted tree. The tree starts with a single node numbered 1, and each node has a numerical value, initially 0.

codeforcescompetitive-programmingdata-structuresdfs-and-similartrees
CF 1891E - Brukhovich and Exams

We are given a sequence of exams with known difficulties. Smilo considers consecutive exams with coprime difficulties unpleasant. The "sadness" of the year is the total number of consecutive exam pairs whose greatest common divisor is one.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathsortings
CF 1891A - Sorting with Twos

We are given an array of integers, and the only operation allowed is a kind of prefix subtraction. Specifically, you can pick a prefix of length $2^m$ for any non-negative integer $m$ such that $2^m le n$, and subtract 1 from every element in that prefix.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1891D - Suspicious logarithms

Working

codeforcescompetitive-programmingbinary-searchbrute-forcemath
CF 1891C - Smilo and Monsters

We are given several independent scenarios. In each scenario, there are multiple groups of enemies, each group having some initial size.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedysortingstwo-pointers
CF 1891B - Deja Vu

We have an array of positive integers and a sequence of queries. A query with value x examines every array element. If an element is divisible by 2^x, we add 2^(x-1) to that element.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1893E - Cacti Symphony

We are asked to assign weights from 1 to 3 to every vertex and edge of a graph that is connected and has a very particular structure: any two simple cycles are vertex-disjoint.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgraphs
CF 1893D - Colorful Constructive

We are given a multiset of colored cubes. Cube colors are fixed, but we may choose how to distribute them across shelves and in what order they appear on each shelf. For a shelf, the requirement is about the minimum distance between equal colors.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1893C - Freedom of Choice

Working

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1893B - Neutral Tonality

We are given two arrays. The first array is fixed in order, and the second array is a multiset of extra values we are allowed to insert anywhere into the first array, while also being allowed to permute these inserted values arbitrarily before placing them.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingstwo-pointers
CF 1893A - Anonymous Informant

Working

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 1895G - Two Characters, Two Colors

We are given a binary string where each position carries a value depending on how we color it. Every character can be painted either red or blue. If we choose red at position $i$, we earn $ri$. If we choose blue, we earn $bi$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpflowsgreedy
Kvant Math Problem 1518

Let the common intersection point of the altitudes be $H$.

kvantmathematicsolympiad
CF 1895D - XOR Construction

We are given the XOR values between consecutive elements of an unknown permutation. Let the required permutation be $b$. For every adjacent pair, we know $$bi oplus b{i+1} = ai.$$ The array $b$ must contain every integer from $0$ to $n-1$ exactly once.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdata-structuresmathstring-suffix-structurestrees
CF 1895F - Fancy Arrays

We are counting arrays of length n consisting of non-negative integers. Adjacent values may move by at most k in either direction. An array is considered fancy if at least one element belongs to the interval $$[x, x+k-1].$$ The task is to count all such arrays modulo $10^9+7$.

codeforcescompetitive-programmingcombinatoricsdpmathmatrices
CF 1895E - Infinite Card Game

Each test case describes two players who each own a fixed set of cards. Every card has two numbers, an attack and a defence. A card can defeat another card if its attack is strictly greater than the other card’s defence. The game starts when Monocarp chooses one of his cards.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardpdsugamesgraphsgreedysortingstwo-pointers
CF 1895A - Treasure Chest

The number line contains three important positions. Monocarp starts at position 0, the chest is at position x, and the key is at position y. To open the chest, Monocarp must eventually be standing at the same position as the chest while already carrying the key.

codeforcescompetitive-programmingmath
CF 1895B - Points and Minimum Distance

We start with a multiset of $2n$ integers. The task is to use every number exactly once and pair them up, forming $n$ ordered pairs. Each pair becomes a point in the plane, where the two values are interpreted as its $x$ and $y$ coordinates.

codeforcescompetitive-programminggreedymathsortings
CF 1895C - Torn Lucky Ticket

We are given a collection of ticket fragments, each represented as a string of digits from 1 to 9. A lucky ticket is defined as a string of even length where the sum of digits in the first half equals the sum in the second half.

codeforcescompetitive-programmingbrute-forcedphashingimplementationmath
CF 1896G - Pepe Racing

There are $n^2$ racers with distinct speeds. A race may contain exactly $n$ racers, and the only information returned is the winner of that race.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractivesortings
CF 1896H1 - Cyclic Hamming (Easy Version)

We are given two binary strings, both of length $2^{k+1}$. Some positions are fixed as 0 or 1, while others are unknown and marked with a question mark.

codeforcescompetitive-programmingbrute-forcedivide-and-conquerdpfftmathnumber-theory
CF 1896H2 - Cyclic Hamming (Hard Version)

Let $n = 2^{k+1}$. We must fill the question marks in two binary strings $s$ and $t$, each of length $n$, so that both strings contain exactly $n/2$ zeros and $n/2$ ones. The second condition is much more interesting.

codeforcescompetitive-programmingbrute-forcedpfftmathnumber-theory
CF 1896F - Bracket Xoring

Working

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1896D - Ones and Twos

We are given an array consisting only of 1s and 2s, and the array changes over time. Between changes, we are repeatedly asked a yes/no question: whether there exists a contiguous subarray whose sum is exactly some target value. The key difficulty is that the array is not static.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquermathtwo-pointers
CF 1896E - Permutation Sorting

We are given a permutation of 1...n. Some positions are already correct, meaning a[i] = i. These positions are called good. Every second, we look only at the positions that are still not good. Their values are cyclically shifted one step to the right among those positions.

codeforcescompetitive-programmingdata-structuressortings
CF 1896C - Matching Arrays

We have two arrays of equal length. Array a is fixed, while array b may be rearranged arbitrarily. After choosing a permutation of b, we compare the arrays position by position. The beauty of the resulting pair of arrays is the number of indices where a[i] b[i].

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedysortings
CF 1896A - Jagged Swaps

We are given a permutation and a very specific swap operation. A swap is allowed only at a position i where the element is a local maximum. In other words, a[i] must be larger than both of its neighbors.

codeforcescompetitive-programmingsortings
CF 1896B - AB Flipping

We are given a string consisting only of two characters, A and B, which can be thought of as a line of adjacent tiles. The only allowed move is to pick a position where an A is immediately followed by a B, and swap them so that the A moves one step to the right.

codeforcescompetitive-programminggreedystringstwo-pointers
CF 1898F - Vova Escapes the Matrix

We are given an $n times m$ grid representing a room where Vova is trapped. Each cell is either empty, blocked, or contains Vova. He can move to any empty cell sharing a side, and he can escape if he reaches an empty cell on the boundary of the grid.

codeforcescompetitive-programmingbrute-forcedfs-and-similardivide-and-conquershortest-paths
CF 1898E - Sofia and Strings

We are given two strings, s and t. The task is to determine whether it is possible to transform s into t using two operations: removing any character from s or sorting any substring of s alphabetically.

codeforcescompetitive-programmingdata-structuresgreedysortingsstringstwo-pointers
CF 1898C - Colorful Grid

We are asked to color the segments of a rectangular grid, formed by $n$ horizontal lines and $m$ vertical lines, using two colors, red and blue. Each segment connects two adjacent points either horizontally or vertically.

codeforcescompetitive-programmingconstructive-algorithms
CF 1898A - Milica and String

We are given a string consisting only of the characters A and B. The goal is to transform this string so that it contains exactly k occurrences of B.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1898B - Milena and Admirer

We start with an array of positive integers. The only allowed operation is to pick one element and split it into two positive parts whose sum equals the original value. Each split increases the array length by one.

codeforcescompetitive-programminggreedymath
CF 1899F - Alex's whims

We are given a tree with $n$ nodes, but the tree is not fixed in its usefulness. Over $q$ days, a value $di$ is announced, and each day we must ensure that the current tree contains at least one pair of leaves whose distance is exactly $di$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyshortest-pathstrees
CF 1899G - Unusual Entertainment

We have a rooted tree with root at vertex 1. A permutation p contains every vertex exactly once. Each query gives three values (l, r, x). We look at the vertices appearing in the permutation segment p[l...

codeforcescompetitive-programmingdata-structuresdfs-and-similardsushortest-pathssortingstreestwo-pointers
CF 1899E - Queue Sort

We are given an array of integers, and we want to sort it in non-decreasing order. The catch is that we cannot arbitrarily swap elements.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1899D - Yarik and Musical Notes

We are given a sequence of integers a1, a2, ..., an, where each integer represents the exponent of 2 forming a musical note: bi = 2^{ai}. Yarik defines a combination of two notes (bi, bj) as bi^{bj}.

codeforcescompetitive-programminghashingmathnumber-theory
CF 1899B - 250 Thousand Tons of TNT

The problem asks us to find the maximum possible weight difference between two trucks when loading boxes of TNT. We have a row of boxes with given weights, and we can choose any truck size $k$ from 1 to $n$ as long as it divides $n$.

codeforcescompetitive-programmingbrute-forceimplementationnumber-theory
CF 1899C - Yarik and Array

We are given several independent test cases. Each test case provides an integer array, and the task is to choose a non-empty contiguous segment whose sum is as large as possible, under one additional restriction: adjacent elements inside the chosen segment must alternate in…

codeforcescompetitive-programmingdpgreedytwo-pointers
CF 1899A - Game with Integers

We are asked to analyze a simple two-player game with integers. The game starts with a number $n$. Vanya moves first, and each player can either increment or decrement the number by 1 on their turn. Vanya wins immediately if, after his move, the number becomes divisible by 3.

codeforcescompetitive-programminggamesmathnumber-theory
CF 1900F - Local Deletions

We are given a permutation of numbers from 1 to $n$ and a sequence of queries asking for the result of repeatedly deleting local minima and maxima from subarrays until only one element remains.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementation
CF 1900D - Small GCD

We are given an array of integers, and we need to consider every triple of indices $i < j < k$. For each triple, we take the three values, reorder them conceptually so we can identify the two smallest, and then compute the gcd of those two smallest values only.

codeforcescompetitive-programmingbitmasksbrute-forcedpmathnumber-theory
CF 1900C - Anji's Binary Tree

We are given a rooted binary tree. Every node contains one character: - 'L' means "go to the left child" - 'R' means "go to the right child" - 'U' means "go to the parent" If the requested destination does not exist, the traveler stays where he is.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1900E - Transitive Graph

The original graph gives directed connections between vertices, and then we repeatedly “complete” it under a transitive rule: whenever there is a path of length two from a vertex $a to b to c$, we eventually add a direct edge $a to c$.

codeforcescompetitive-programmingdfs-and-similardpdsugraphsimplementation
CF 1900A - Cover in Water

We are given a line of cells where each position is either usable or blocked. Only usable positions can ever hold water, while blocked ones act as permanent walls that split the line into independent regions.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationstrings
CF 1900B - Laura and Operations

The problem presents a set of digits consisting of only 1, 2, and 3. We are given counts a, b, and c for each digit, representing the number of times 1, 2, and 3 appear on the board, respectively.

codeforcescompetitive-programmingdpmath
Kvant Math Problem 1512

Let $f(x)=a_nx^n+a_{n-1}x^{n-1}+\cdots+a_0$ with $a_n\ne 0$, and define for a natural number $k$

kvantmathematicsolympiad
CF 1901E - Compressed Tree

We are given a tree with n vertices, each labeled with an integer. The operations allowed let us remove leaf vertices (vertices with at most one edge) any number of times.

codeforcescompetitive-programmingdfs-and-similardpgraphsgreedysortingstrees
CF 1901F - Landscaping

We are given a road represented as a sequence of points along the x-axis, starting at (0,0) and ending at (n-1,0). Each point has a height above the x-axis, initially given by array a.

codeforcescompetitive-programmingbinary-searchgeometrytwo-pointers
CF 1901D - Yet Another Monster Fight

We are asked to determine the minimum initial power $x$ of a chain lightning spell that can defeat a row of monsters no matter how the spell propagates, provided we choose the first monster to hit optimally.

codeforcescompetitive-programmingbinary-searchdpgreedyimplementationmath
CF 1901C - Add, Divide and Floor

We are given an array of non-negative integers. In a single operation, we can choose a number $x$ and add it to each element, then divide each element by 2, rounding down. This affects all elements simultaneously.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1901B - Chip and Ribbon

We are asked to simulate a chip moving along a ribbon of cells, where each cell initially contains zero. On the first turn, the chip starts at the first cell, and on every subsequent turn, we can either move it to the next cell or teleport it to any cell.

codeforcescompetitive-programminggreedymath
CF 1901A - Line Trip

We are moving along a straight road from position 0 to position x and then returning back to 0. The car consumes fuel proportional to distance, one unit of fuel per unit of distance.

codeforcescompetitive-programminggreedymath
CF 1902F - Trees and XOR Queries Again

We are given a tree with n vertices, where each vertex carries an integer value. A tree is an acyclic connected graph, which ensures there is exactly one simple path between any two vertices.

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquergraphsimplementationmathtrees
CF 1902E - Collapsing Strings

We are given a list of $n$ strings, each consisting of lowercase letters. We are asked to compute the sum of lengths of all pairwise “collapsed” concatenations, where the collapse removes consecutive repeated letters at the junction of two strings.

codeforcescompetitive-programmingdata-structuresstringstrees
CF 1902D - Robot Queries

We are given a fixed sequence of moves of a robot on an infinite grid, where each character moves the robot by one unit in one of the four cardinal directions. For every query, we conceptually modify this path by reversing a single contiguous segment of the command string.

codeforcescompetitive-programmingbinary-searchdata-structuresdpimplementation