brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 2114A - Square Year

We are given a four-digit year as a string, potentially including leading zeros, and we are asked to determine if this number can be expressed as the square of the sum of two non-negative integers.

codeforcescompetitive-programmingbinary-searchbrute-forcemath
Kvant Math Problem 672

Let $f(n)=2^n-1$.

kvantmathematicsolympiad
CF 2115F1 - Gellyfish and Lycoris Radiata (Easy Version)

We are asked to maintain an array of n sets under a sequence of q online operations, where each operation modifies some prefix of sets or deletes a specific element from all sets, and then asks for the smallest element in a particular set.

codeforcescompetitive-programmingdata-structures
CF 2115E - Gellyfish and Mayflower

We are asked to navigate a directed acyclic graph (DAG) with vertices numbered from 1 to n. Each vertex contains a trader who sells cards with a given power for a given cost.

codeforcescompetitive-programmingdpgraphs
CF 2115A - Gellyfish and Flaming Peony

We start with a sequence of positive integers. In one move, we pick two different positions, say $i$ and $j$, and we overwrite $ai$ with the greatest common divisor of its current value and $aj$. The second element $aj$ stays unchanged.

codeforcescompetitive-programmingconstructive-algorithmsdpmathnumber-theory
Kvant Math Problem 575

Let $A_0A_1,\dots,A_{n-1}A_n$ be consecutive segments on a line with each length at most $1$.

kvantmathematicsolympiad
CF 2117D - Retaliation

We are given an array of positive integers, and the goal is to repeatedly apply one of two operations to reduce every element to zero. The first operation subtracts each element by its 1-based index, and the second subtracts each element by its "reverse index" (n minus i plus 1).

codeforcescompetitive-programmingbinary-searchmathnumber-theory
CF 2117A - False Alarm

We are given a sequence of doors arranged in a line. Each door is either open or closed. Yousef starts before the first door and must move strictly from door 1 to door n in order.

codeforcescompetitive-programminggreedyimplementation
CF 2118F - Shifts and Swaps

We are asked whether one array of integers, a, can be transformed into another array, b, using two types of operations. The first operation is a cyclic left shift, which moves every element one position to the left and wraps the first element to the end.

codeforcescompetitive-programmingdata-structuresgraphshashingtrees
CF 2118E - Grid Coloring

We have an odd-sized rectangular grid. Cells are colored one at a time. Whenever a new cell is colored, we look only at the cells that were already colored before this step. Among those cells, every cell that is farthest from the newly colored one receives one penalty.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedymath
CF 2118D1 - Red Light, Green Light (Easy version)

We have a one-dimensional strip of length up to $10^{15}$, along which certain cells contain traffic lights. Each light has a fixed period $k$ and a delay $di < k$, and it turns red at times $l cdot k + di$ for integer $l ge 0$. All other times, the light is green.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphsimplementationnumber-theory
CF 2118D2 - Red Light, Green Light (Hard version)

We are asked to simulate motion along a one-dimensional strip of length up to $10^{15}$, where certain cells contain traffic lights with periodic red signals. Each traffic light has a fixed period $k$ and a delay $di$, meaning it shows red at times $t$ where $t mod k = di$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardpgraphsimplementationmathnumber-theory
CF 2118C - Make It Beautiful

We are given an array of integers. Each integer has a "beauty" defined as the number of 1s in its binary representation. For example, 5 in binary is 101, which has two 1s, so its beauty is 2. The total beauty of the array is the sum of the beauties of all its elements.

codeforcescompetitive-programmingbitmasksdata-structuresgreedymath
CF 2118B - Make It Permutation

We start with an $n times n$ matrix where every row is identical and equal to the sequence $1,2,3,dots,n$. So initially every column is constant, and no column is a permutation at all.

codeforcescompetitive-programmingconstructive-algorithms
CF 2118A - Equal Subsequences

We are asked to construct a binary string of length $n$, containing exactly $k$ ones, with an additional structural constraint involving subsequences of length three.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2119F - Volcanic Eruptions

We are given a rooted tree where every node carries a value of either +1 or −1. A lava wave starts from the root and expands outward one edge per time unit, so at time t every node at distance at most t from the root is already unsafe.

codeforcescompetitive-programmingdfs-and-similardpgreedyshortest-pathstrees
Kvant Math Problem 500

Label the people $1,2,\dots,N$ from left to right.

kvantmathematicsolympiad
CF 2119E - And Constraint

We are given two sequences, a of length n-1 and b of length n. The goal is to increase elements in b using the fewest increments so that for every adjacent pair (bi, b{i+1}), their bitwise AND equals ai.

codeforcescompetitive-programmingbitmasksdpgreedy
CF 2119D - Token Removing

We are given sequences where each position i can store a value a[i] between 0 and i inclusive. Think of the index i as a time step and also as the right endpoint of a segment. Now interpret the process that defines the weight.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2119C - A Good Problem

We are asked to construct an array of length n using integers within a given range [l, r], such that the bitwise AND of all elements equals the bitwise XOR of all elements. We do not need to output the full array; only the k-th element in lexicographical order.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 2119A - Add or XOR

We are given two non-negative integers a and b and two operations that can transform a. The first operation increments a by one at a cost x. The second operation flips the least significant bit of a (using a XOR 1) at a cost y.

codeforcescompetitive-programmingbitmasksgreedymath
CF 2119B - Line Segments

We are given two fixed points on a plane: a starting location and a destination. We also receive a sequence of movement lengths. At step i, we must move from our current position to any point whose Euclidean distance from the current position is exactly ai.

codeforcescompetitive-programminggeometrygreedymath
CF 2120G - Eulerian Line Graph

We are given a simple, connected graph $G$ with $n$ vertices and $m$ edges, and we are asked to examine the properties of its iterated line graph $L^k(G)$.

codeforcescompetitive-programminggraphsgreedymath
CF 2120E - Lanes of Cars

Each lane initially contains ai cars. If nobody moves, the cars in a lane leave one per second, so a lane of size x contributes $$1+2+dots+x=frac{x(x+1)}2$$ to the total angriness. Cars may switch lanes.

codeforcescompetitive-programmingbinary-searchdpternary-search
CF 2120F - Superb Graphs

We are given several graphs on the same vertex set. For each graph, we can imagine a "superb graph" as a compressed version in which vertices of the superb graph correspond either to independent sets or cliques of the original graph.

codeforcescompetitive-programming2-satgraphs
CF 2120D - Matrix game

We are asked to determine the smallest size of a matrix Aryan should request from Harshith to guarantee that Aryan can always find a submatrix of size $a times b$ filled with identical numbers.

codeforcescompetitive-programmingcombinatoricsmath
CF 2120C - Divine Tree

We are asked to construct a rooted tree of n nodes with a special property: each node has a divineness, which is the smallest node label on the path from the root to that node.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortingstrees
CF 2120A - Square of Rectangles

We are given three axis-aligned rectangles. Their dimensions are already ordered so that $$l3 le l2 le l1$$ and $$b3 le b2 le b1.$$ The rectangles cannot be rotated.

codeforcescompetitive-programminggeometrymath
CF 2120B - Square Pool

We are given a square pool table of side length $s$ with pockets at the four corners. On this table, $n$ balls are placed at integer coordinates strictly inside the table, never on the edges or corners.

codeforcescompetitive-programminggeometry
CF 2121F - Yamakasi

We are given an integer array and, for each test case, two target values: a required subarray sum s and a required maximum value x. The task is to count how many contiguous subarrays have total sum exactly equal to s and whose largest element is exactly x.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedytwo-pointers
CF 2121G - Gangsta

We are asked to process a binary string and compute, for every contiguous substring, the maximum frequency of either 0 or 1 in that substring, then sum these values across all substrings.

codeforcescompetitive-programmingdata-structuresdivide-and-conquermathsortings
Kvant Math Problem 456

At each vertex of the polyhedron, exactly three edges meet, so the vertex figure is a trihedral angle.

kvantmathematicsolympiad
CF 2121D - 1709

We are given two arrays, a and b, each of length n, containing all integers from 1 to 2n exactly once between them. The task is to rearrange the arrays using three types of swaps so that a is strictly increasing, b is strictly increasing, and at each position i, a[i] < b[i].

codeforcescompetitive-programmingimplementationsortings
CF 2121E - Sponsor of Your Problems

We are given two integers of equal length in decimal form, and we are allowed to pick any integer x that lies within the inclusive range between them.

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 2121C - Those Who Are With Us

We are given a rectangular grid of integers. In one move, we pick a single row and a single column. Every cell that lies in that chosen row or that chosen column gets decreased by one, with the intersection cell counted only once.

codeforcescompetitive-programminggreedyimplementation
CF 2121B - Above the Clouds

We are asked to determine, for a given string, whether it is possible to split it into three non-empty parts, $a$, $b$, and $c$, such that $a + b + c = s$ and the middle segment $b$ appears as a substring of the concatenation $a + c$.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 2121A - Letter Home

We are given a set of distinct integer positions on the number line and a starting position. From the starting position, we can move left or right by one unit at a time.

codeforcescompetitive-programmingbrute-forcemath
CF 2122F - Colorful Polygon

We are given a small array of integers $a = [a1, a2, dots, an]$, with $n le 8$ and a total sum $S = a1 + dots + an le 100$.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquergeometry
CF 2122G - Tree Parking

We are asked to count valid parking schedules for cars on a tree. Each vertex of the tree will eventually host one car.

codeforcescompetitive-programmingcombinatoricsfftmathtrees
CF 2122E - Greedy Grid Counting

We are given a $2 times n$ grid with some cells already filled with integers between $1$ and $k$, while other cells are empty.

codeforcescompetitive-programmingcombinatoricsdpgreedymath
CF 2122B - Pile Shuffling

We are given several piles of tiles, each containing some zeros stacked on top of ones. For each pile, we know both the initial configuration and the target configuration, where the target also consists of some zeros on top of some ones.

codeforcescompetitive-programminggreedymath
CF 2122D - Traffic Lights

The problem describes a connected, simple undirected graph with n vertices and m edges. A token starts at vertex 1 at time 0. At each integer second t, if the token is at vertex u, you have two choices: either wait one second at u, or move along a specific edge of u.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpgraphsgreedyshortest-paths
CF 2122C - Manhattan Pairs

We are given a set of points on a 2D plane, and the number of points is always even. Our task is to pair all points into disjoint pairs such that the sum of Manhattan distances between the points in each pair is maximized.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedymathsortings
CF 2122A - Greedy Grid

We are working on a grid where each cell contains a nonnegative number, and we are only allowed to move either right or down starting from the top-left corner. Any such path from the top-left to the bottom-right has a total score equal to the sum of all visited cells.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2123F - Minimize Fixed Points

We are asked to construct a permutation of integers from $1$ to $n$ such that for every position $i$ from $2$ to $n$, the greatest common divisor of the position and its value, $gcd(pi, i)$, is strictly greater than $1$.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
Kvant Math Problem 276

A direct synthetic approach would require tracking the foot of a perpendicular from $B$ to the line $PC$, which suggests that a coordinate representation or vector projection will likely reduce the co…

kvantmathematicsolympiad
CF 2123G - Modular Sorting

We are maintaining an array that changes over time, and we are asked to answer two kinds of queries. One type permanently updates a single position in the array.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathnumber-theorysortings
CF 2123D - Binary String Battle

We are given a binary string. Two players alternate moves, with Alice moving first. The game evolves by repeatedly rewriting parts of the string.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 2123E - MEX Count

We are given an array of nonnegative integers, and we are asked to compute the number of distinct possible values of the minimum excluded value (MEX) after removing exactly $k$ elements from the array, for each $k$ from 0 to $n$.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingstwo-pointers
CF 2123B - Tournament

We have a tournament with n players. Player i has strength a[i]. Repeatedly, two surviving players are selected, and the weaker one is eliminated. If both strengths are equal, either one may be eliminated. The process stops when exactly k players remain.

codeforcescompetitive-programminggreedy
CF 2123A - Blackboard Game

The blackboard initially contains every integer from 0 to n - 1. A round always has two moves. First Alice removes some number a. Then Bob must remove a different number b such that $$a+b equiv 3 pmod 4.$$ If Bob cannot find such a number, the game ends immediately and Bob loses.

codeforcescompetitive-programmingmath
CF 2123C - Prefix Min and Suffix Max

We are given an array of distinct integers and a set of operations: you can either replace a prefix with its minimum or a suffix with its maximum.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 2124I - Lexicographic Partition

Codeforces 2124I: Lexicographic Partition

codeforcescompetitive-programmingconstructive-algorithmsmathtrees
CF 2124H - Longest Good Subsequence

We are given an array a. We want to choose a subsequence and reinterpret it as a new array b. The goal is to maximize the length of b, subject to b being a good array. The definition of goodness is written in terms of a permutation and range minimums.

codeforcescompetitive-programmingdpmathtrees
CF 2124F2 - Appending Permutations (Hard Version)

We are building an array of length $n$, but we are not constructing it element by element. Instead, the array is formed by repeatedly appending whole blocks. Each block is a cyclic rotation of the permutation $[1, 2, ldots, s]$ for some chosen length $s$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2124G - Maximise Sum

I can't honestly produce a correct "complete solution editorial" for Codeforces 2124G from the information available here.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 2124D - Make a Palindrome

We start with an array and may repeatedly delete elements. The deletion rule is unusual: choose any subarray of length at least k, find its k-th smallest value, and delete one occurrence of that value inside the chosen subarray.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 2124F1 - Appending Permutations (Easy Version)

We are asked to count arrays of length $n$ that can be built by repeatedly appending cyclic shifts of the arrays $[1, 2, dots, s]$ for any $s ge 1$, while respecting a set of restrictions of the form $ai ne x$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2124E - Make it Zero

We are given an array of positive integers, and our only allowed action is to repeatedly subtract a carefully chosen auxiliary array from it.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2124A - Deranged Deletions

We are given an array and may delete any number of elements while preserving the relative order of the remaining ones. After the deletions, the remaining sequence must be non-empty.

codeforcescompetitive-programminggreedysortings
CF 2124B - Minimise Sum

We are given an array and we repeatedly look at prefix minimums: at position 1 we take the minimum of the first element, at position 2 we take the minimum over the first two elements, and so on until the full prefix. The final value is the sum of all these prefix minima.

codeforcescompetitive-programminggreedy
CF 2124C - Subset Multiplication

We are given an array b that was generated from an unknown “beautiful” array a, where each element divides the next. Bob then chose an integer x and multiplied some subset of a’s elements by x to form b. Our task is to recover any valid x.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 2125F - Timofey and Docker

Timofey has written a text s and wants to present it to a conference audience. Each attendee understands the topic if the number of times the substring "docker" appears consecutively in s falls within their personal interval [li, ri].

codeforcescompetitive-programmingbinary-searchdivide-and-conquerdp
CF 2125E - Sets of Complementary Sums

The problem asks us to count sets of integers that can be generated as complementary sums from some array of positive integers.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathtwo-pointers
CF 2125D - Segments Covering

We are working with a line of $m$ cells. Each cell must end up being covered by exactly one chosen interval. There are $n$ candidate segments. Each segment $i$ covers a contiguous range $[li, ri]$, but it is not guaranteed to exist.

codeforcescompetitive-programmingdpmathprobabilities
CF 2125A - Difficult Contest

We are given several strings consisting of uppercase letters. Each letter represents a contest problem. A contest is considered difficult if the string contains either "FFT" or "NTT" as a contiguous substring. We may rearrange the letters of the string in any order.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortingsstrings
CF 2125C - Count Good Numbers

A number is called good if none of the primes in its prime factorization are single digit primes. The only single digit primes are 2, 3, 5, and 7, so a number is good exactly when it is not divisible by any of these four primes.

codeforcescompetitive-programmingbitmaskscombinatoricsmathnumber-theory
CF 2125B - Left and Down

We start with a robot placed at a coordinate $(a,b)$ on an infinite grid, and we want to move it back to the origin $(0,0)$.

codeforcescompetitive-programmingmathnumber-theory
CF 2126G2 - Big Wins! (hard version)

We are given an array of integers, each between 1 and $n$, and we need to choose a contiguous subarray that maximizes the difference between its median and its minimum element.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdsutreestwo-pointers
CF 2126G1 - Big Wins! (easy version)

We are asked to find, for each array, a contiguous segment whose median minus its minimum is as large as possible. Formally, for a subarray $a[l, r]$, we calculate the median of its elements after sorting, then subtract the smallest element in that segment.

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsutwo-pointers
CF 2126F - 1-1-1, Free Tree!

We are given a tree where every vertex has a color and every edge has a weight. An edge contributes its weight to the total cost only when its endpoints currently have different colors; if the endpoints share the same color, the edge contributes nothing. The process is dynamic.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similargraphsimplementationtrees
CF 2126E - G-C-D, Unlucky!

We are given two arrays of integers, p and s, each of length n. Array p represents the prefix GCDs of some unknown array a, and array s represents the suffix GCDs of the same array. The task is to decide whether such an array a exists.

codeforcescompetitive-programmingmathnumber-theory
CF 2126D - This Is the Last Time

We are given a sequence of casinos, each defined by a range of coins [li, ri] that we must have to play, and a fixed result reali that becomes our new coin count after playing there. We start with k coins and can visit casinos in any order, but only once each.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 2126B - No Casino in the Mountains

We are given a sequence of days, each labeled either as rainy (1) or good (0). Jean wants to complete as many hikes as possible. Each hike takes exactly k consecutive days of good weather, and after finishing a hike, he must rest for at least one day before starting another.

codeforcescompetitive-programmingdpgreedy
CF 2126A - Only One Digit

The task asks us to find the smallest non-negative integer that shares at least one decimal digit with a given number. For every test case, we are provided a number x, and we need to produce a number y such that some digit in y also appears in x.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 2127H - 23 Rises Again

We are given an undirected, connected graph with up to 30 vertices, where each vertex belongs to at most 5 simple cycles. A simple cycle here is a closed path where each vertex has exactly two neighbors.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpflowsgraph-matchingsgraphsgreedyimplementationprobabilitiestrees
CF 2128C - Leftmost Below

We start with an array of length n, filled with zeros. An operation chooses a positive integer x that is strictly larger than the current minimum value in the array. The operation does not let us choose which position receives the increment.

codeforcescompetitive-programminggreedymath
CF 2128A - Recycling Center

We are given several independent scenarios. In each scenario there is a collection of bags, each with an initial weight. Time proceeds in discrete seconds. At every second we are forced to remove exactly one remaining bag.

codeforcescompetitive-programminggreedysortings
CF 2129F2 - Top-K Tracker (Hard Version)

We are given a hidden permutation of integers from 1 to $n$, and we can only access it indirectly through interactive queries. There are four types of queries.

codeforcescompetitive-programminginteractive
CF 2129F1 - Top-K Tracker (Easy Version)

We are asked to recover a hidden permutation of the numbers from 1 to $n$ through a limited set of interactive queries.

codeforcescompetitive-programminginteractive
CF 2129C3 - Interactive RBS (Hard Version)

We are given a hidden binary string made of opening and closing brackets, and we are allowed to probe it indirectly.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsdpinteractive
CF 2129E - Induced Subgraph Queries

We are given a simple undirected graph whose vertices are labeled from 1 to n. The label itself is also the index of the vertex. The graph does not change, but each query focuses only on a contiguous segment of vertices, from l to r.

codeforcescompetitive-programmingdata-structuresgraphssortings
CF 2129D - Permutation Blackhole

We are given a permutation of numbers from 1 to $n$, and a process that colors these numbers one by one in the order of the permutation. Each cell starts white with a score of zero.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpimplementationmath
CF 2129C2 - Interactive RBS (Medium Version)

We are given a hidden string made only of opening and closing parentheses. We cannot see it directly. Instead, we can query any multiset-like sequence of indices, and the judge constructs a new string by taking the characters at those indices in order.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2129C1 - Interactive RBS (Easy Version)

We are given a hidden bracket sequence of length $n$, consisting only of '(' and ')'. The goal is to reconstruct this sequence by asking at most 550 interactive queries.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2129B - Stay or Mirror

We are given a permutation of integers from 1 to n. For each element in this permutation, we are allowed to either leave it as-is or replace it with its “mirror” with respect to 2n, defined as $2n - pi$.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 2129A - Double Perspective

We are given a collection of segments on a line, each segment also acting as an edge between two vertices. From this set we must choose some subset of edges. Two different quantities are computed from the chosen subset.

codeforcescompetitive-programmingconstructive-algorithmsdpdsugraphsgreedysortings
CF 2130A - Submission is All You Need

We are given a multiset of non-negative integers, which we can think of as a bag of numbered tiles. Our goal is to repeatedly choose subsets of tiles and increase a score using one of two rules: either add the sum of the chosen tiles to the score, or add the minimum excluded…

codeforcescompetitive-programminggreedymath
CF 2131G - Wafu!

We start with a finite set of distinct positive integers. A single move depends entirely on the current minimum element of the set.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdfs-and-similardpmath
CF 2131H - Sea, You & copriMe

The problem gives us an array of integers, each between 1 and some upper bound $m$, and asks us to find four distinct indices $p, q, r, s$ such that the pair $(ap, aq)$ and the pair $(ar, as)$ are both coprime.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsgreedymathnumber-theory
CF 2131F - Unjust Binary Life

We are given two binary strings, a and b, each of length n. They define a virtual n × n grid where each cell (i, j) contains the value a[i] XOR b[j]. Yuri starts at the top-left cell (1,1) and can only move either right or down.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymathsortingstwo-pointers
CF 2131E - Adjacent XOR

We are given two arrays, a and b, both of length n. We can perform an operation on a at most once per index: for any index i from 1 to n-1, we can set a[i] to a[i] XOR a[i+1].

codeforcescompetitive-programmingbrute-forcegreedy
CF 2131D - Arboris Contractio

We are given a tree, an undirected connected graph with no cycles. Kagari can perform an operation that "re-roots" a path: choose two vertices, remove the edges along the path connecting them, and then reconnect all vertices along that path directly to the starting vertex.

codeforcescompetitive-programmingdata-structuresgraphsgreedytrees
CF 2131B - Alternating Series

We need to construct an integer array of length n with two properties. The first property says neighboring elements must always have opposite signs. Since their product must be negative, neither element can be zero, and the signs must alternate.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2131C - Make it Equal

We start with a multiset $S$ of size $n$ and we want to transform it into another multiset $T$ of the same size. The only allowed move takes one element $x$ from $S$, deletes it, and replaces it with either $x+k$ or $ The core question is whether repeated applications of these…

codeforcescompetitive-programmingmathnumber-theory
CF 2131A - Lever

We are given two arrays of equal length, a and b, and a machine called The Lever that iterates a process in which it adjusts the elements of a toward the elements of b.

codeforcescompetitive-programmingmath
CF 2132G - Famous Choreographer

We are given a rectangular grid of ballerinas, each performing one of 26 possible movements represented by lowercase English letters. Conceptually, each row is a string, and the entire grid is an array of strings.

codeforcescompetitive-programminghashingimplementationstrings
CF 2132F - Rada and the Chamomile Valley

We are asked to analyze a connected undirected graph representing the Chamomile Valley, where nodes are houses and edges are lanes between them. Rada wants to know which lanes are guaranteed to be part of every shortest path from house 1 to house n.

codeforcescompetitive-programmingdfs-and-similargraphsshortest-paths
CF 2132C2 - The Cunning Seller (hard version)

Each deal lets us buy exactly $3^x$ watermelons for $$3^{x+1} + x cdot 3^{x-1}$$ coins. We need to buy exactly $n$ watermelons. We may use at most $k$ deals. Among all valid ways to do that, we want the minimum total cost.

codeforcescompetitive-programmingbinary-searchgreedymath
CF 2132E - Arithmetics Competition

The problem presents a team of two players, Vadim and Kostya, who each have a collection of cards with numeric values.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingsternary-search