brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1970D1 - Arithmancy (Easy)

We are asked to play the role of Professor Vector in an interactive problem. Our task is twofold. First, we need to generate n distinct magic words consisting only of X and O.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsinteractivestrings
CF 1970C3 - Game on Tree (Hard)

We are given a tree of n nodes, and multiple rounds of a two-player game. In each round, a stone starts on one node. Players alternate moves, moving the stone to an unactivated neighbor and marking that neighbor as activated. The player who cannot move loses.

codeforcescompetitive-programmingdfs-and-similardpgamestrees
CF 1970C2 - Game on Tree (Medium)

We are given a tree where every node is initially unused. A single stone is placed on a chosen starting node. From that moment, players alternate moves, starting with Ron. A move consists of sliding the stone along an edge to a neighboring node that has never been visited before.

codeforcescompetitive-programmingdfs-and-similardpgamestrees
CF 1970C1 - Game on Tree (Easy)

The structure we are given is not an arbitrary tree in the usual sense, but a very restricted one: it has exactly two leaves. That means every node has degree at most two, except possibly some internal nodes, and the whole graph is essentially a single chain.

codeforcescompetitive-programminggames
CF 1970B3 - Exact Neighbours (Hard)

We are asked to place n wizard houses on an n × n grid such that two conditions are met. First, no two houses can occupy the same column; this ensures that each wizard has an unobstructed view north and south.

codeforcescompetitive-programmingconstructive-algorithms
CF 1970B2 - Exact Neighbours (Medium)

We are asked to place $n$ wizard houses on an $n times n$ grid such that each wizard can reach another wizard’s house at a prescribed Manhattan distance $ai$, and no two houses share the same column.

codeforcescompetitive-programmingconstructive-algorithms
CF 1970B1 - Exact Neighbours (Easy)

We are asked to place n wizard houses on an n x n grid such that each house occupies a unique row and column, and each wizard has a target distance ai that they want to travel to another house during the weekend.

codeforcescompetitive-programmingconstructive-algorithms
CF 1970A2 - Balanced Unshuffle (Medium)

The task is to invert the so-called balanced shuffle operation on a balanced parentheses string. You are given a string s of parentheses that is guaranteed to be balanced.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmstrees
CF 1970A3 - Balanced Unshuffle (Hard)

We are given a single valid parentheses sequence, meaning it contains the same number of opening and closing brackets and never drops below zero balance in any prefix.

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 1970A1 - Balanced Shuffle (Easy)

We are given a string composed solely of opening and closing parentheses. The string is guaranteed to be a balanced parentheses sequence, which means the total number of "(" matches the number of ")" and every prefix of the string has at least as many "(" as ")".

codeforcescompetitive-programmingimplementationsortings
CF 1971H - ±1

We are given a 3-row grid with $n$ columns. Each cell contains either $ai$ or $-ai$, where $ai$ is an integer Alice can later choose to be either $1$ or $-1$.

codeforcescompetitive-programming2-satdfs-and-similargraphs
CF 1971F - Circle Perimeter

We are looking at integer grid points on the plane, each point having coordinates $(x, y)$ where both values are integers. For each test case, a radius $r$ is given, and we need to count how many lattice points lie in a thin circular ring centered at the origin.

codeforcescompetitive-programmingbinary-searchbrute-forcedfs-and-similargeometryimplementationmath
CF 1971G - XOUR

We are given an array of nonnegative integers and a special swap condition: two elements can be swapped if the bitwise XOR of their values is less than 4. The goal is to produce the lexicographically smallest array possible by performing any number of such swaps.

codeforcescompetitive-programmingdata-structuresdsusortings
CF 1971E - Find the Car

We are given a car moving along a straight line from position 0 to position n. We know the exact times at which the car passes several checkpoints. These checkpoints are sorted by position: 0, a1, a2, ..., ak, and the corresponding times are also strictly increasing: 0, b1, b2, .

codeforcescompetitive-programmingbinary-searchmathsortings
CF 1971B - Different String

We are given a string of lowercase English letters, and the task is to rearrange its letters to form a new string that is different from the original. The input consists of multiple test cases, each with a single string.

codeforcescompetitive-programmingimplementationstrings
CF 1971D - Binary Cut

We are given a binary string, a sequence of 0s and 1s, and we are asked to partition it into contiguous substrings in such a way that the substrings can later be rearranged to form a sorted binary string, meaning all 0s appear before all 1s.

codeforcescompetitive-programmingdpgreedyimplementationsortingsstrings
CF 1971A - My First Sorting Problem

The task asks us to read pairs of small integers and output each pair in sorted order: the smaller number first, then the larger number.

codeforcescompetitive-programmingimplementationsortings
CF 1971C - Clock and Strings

We are working with a circular arrangement of 12 equally spaced points labeled 1 through 12, like the hours on a clock. Each test case gives four distinct labels a, b, c, d. Alice draws a straight chord between a and b, and Bob draws another chord between c and d.

codeforcescompetitive-programmingimplementation
CF 1977E - Tensor

We are given an interactive problem where there is a hidden directed graph with $n$ vertices, numbered from $1$ to $n$. Each edge in the graph goes "backwards," meaning it connects a higher-numbered vertex $j$ to a lower-numbered vertex $i$ ($i < j$).

codeforcescompetitive-programmingconstructive-algorithmsgraphsinteractive
CF 1977D - XORificator

We are given a matrix of size $n times m$ consisting only of 0s and 1s. We can “flip” any row using a XORificator, which changes every 0 to 1 and every 1 to 0 in that row. After performing any flips, we want to maximize the number of columns that contain exactly one 1.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyhashing
CF 1977C - Nikita and LCM

We are given an array of integers. A subsequence is called special if the least common multiple of all its elements does not appear anywhere in the original array. The task is to find the maximum possible length of such a subsequence.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedymathnumber-theorysortings
CF 1977B - Binary Colouring

We are asked to represent a given positive integer $x$ as a sum of powers of two, but with a strict additional constraint: the coefficients of the powers of two can only be -1, 0, or 1, and no two non-zero coefficients can be adjacent.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 1977A - Little Nikita

Nikita has a tower that starts empty, and he can perform exactly one of two operations per move: either place one cube on top or remove one cube from the top. The problem asks whether, after performing exactly n moves, the tower can have exactly m cubes.

codeforcescompetitive-programmingmath
CF 1978F - Large Graph

We are given an array of integers and asked to build a square matrix where each row is a cyclic right shift of the previous row. Then, we treat every element of the matrix as a vertex in a graph.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsnumber-theorytwo-pointers
CF 1978E - Computing Machine

We are given two binary strings s and t of length n. The strings consist of 0s and 1s. Sasha is interested in the following: for a given substring range [l, r], we consider substring a = s[l..r] and substring b = t[l..r].

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedyimplementation
CF 1978D - Elections

Working

codeforcescompetitive-programmingdata-structuresgreedyimplementationmath
CF 1978C - Manhattan Permutations

We are asked to construct a permutation of integers from $1$ to $n$ such that the sum of absolute differences between each element's value and its position equals a given number $k$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationmath
CF 1978A - Alice and Books

Alice has a stack of books, each with a certain number of pages. She wants to divide them into exactly two piles, making sure both piles are non-empty. From each pile, she will read the book with the most pages.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1978B - New Bakery

In this problem, Bob is trying to maximize his profit from selling buns with a special promotion. He has n buns to sell, a usual price a for each bun, and a promotional parameter b.

codeforcescompetitive-programmingbinary-searchgreedymathternary-search
CF 1979F - Kostyanych's Theorem

We are given an unknown graph that originally was a complete graph on $n$ vertices, but exactly $n-2$ edges were removed. This means the final graph is extremely dense: it has exactly $frac{n(n-1)}{2} - (n-2)$ edges, so it is missing only $n-2$ connections in total.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsinteractive
CF 1979E - Manhattan Triangle

We are given a set of points on a two-dimensional plane, and a positive even integer d. The task is to determine whether we can select three distinct points such that the Manhattan distance between every pair is exactly d.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgeometryimplementationtwo-pointers
CF 1979D - Fixing a Binary String

We are given a binary string of length n and a number k that divides n. The task is to perform exactly one special operation on the string to make it k-proper.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdpgreedyhashingstrings
CF 1979C - Earning on Bets

We are given several independent betting games. In each game, there are n outcomes, and we choose a positive integer number of coins to place on each outcome.

codeforcescompetitive-programmingbinary-searchcombinatoricsconstructive-algorithmsnumber-theory
CF 1979B - XOR Sequences

We are given two integers, x and y. Using them, we define two infinite sequences: $$an=noplus x$$ and $$bn=noplus y.$$ The indices start from 1. Every element is obtained by XORing the index with a fixed value.

codeforcescompetitive-programmingbitmasksgreedy
CF 1979A - Guess the Maximum

In this problem, Alice and Bob play a game with an array of integers. Alice selects a number $k$ and reveals it to Bob. Then Bob picks any subarray of at least two consecutive elements and calculates the maximum value in that subarray. If the maximum exceeds $k$, Alice wins.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1980F1 - Field Division (easy version)

We are asked to divide a rectangular field of size $n times m$ between Alice and Bob. The field contains $k$ fountains at distinct cells, and Alice wants to choose a monotone path-moving only right or down-from the top or left side to the bottom or right side such that she…

codeforcescompetitive-programmingdata-structuresmathsortings
CF 1980G - Yasya and the Mysterious Tree

We are given a tree with n vertices. Each edge in this tree has a weight. There are m queries of two types. The first type changes the effective weights of all edges by XORing them with a given number y.

codeforcescompetitive-programmingbitmasksdata-structuresdfs-and-similargraphsgreedystringstrees
CF 1980F2 - Field Division (hard version)

A monotone path that moves only right and down separates the rectangle into a south-west part owned by Alice and a north-east part owned by Bob. I

codeforcescompetitive-programmingmathsortings
CF 1980D - GCD-sequence

We are given an array of positive integers. From it, we can derive a second array by replacing every adjacent pair with their greatest common divisor. This derived array reflects how “compatible” neighboring values are in terms of shared divisors.

codeforcescompetitive-programminggreedyimplementationmathnumber-theory
Kvant Math Problem 965

Let

kvantmathematicsolympiad
CF 1980C - Sofia and the Lost Operations

We are asked to determine whether a given array b could have been produced from an original array a by applying a sequence of assignment operations where the target indices are lost, but the values assigned in order are known.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1980E - Permutation of Rows and Columns

We are given two rectangular grids of numbers, both of size $n times m$, and together they contain exactly the numbers from $1$ to $n cdot m$, each appearing once. So each matrix is just a rearrangement of the same set of tiles.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyhashingimplementationmathmatricessortings
CF 1980B - Choosing Cubes

We are given several independent scenarios where a collection of numbered cubes is rearranged based on their values. One cube is special because it is the favorite, identified by its original position.

codeforcescompetitive-programmingsortings
CF 1980A - Problem Generator

Each test case describes a small problem set that Vlad already owns and a target number of rounds he wants to organize. Every problem has one of seven possible difficulty labels from A to G.

codeforcescompetitive-programmingmath
CF 1981D - Turtle and Multiplication

We need to construct an array of length n such that every adjacent product is unique. More precisely, the values $$a1a2, a2a3, dots, a{n-1}an$$ must all be different.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsnumber-theory
CF 1981F - Turtle and Paths on a Tree

We are given a rooted tree where every node has a label. The structure is restricted so that each node has at most two children, but otherwise it is still a general rooted tree.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1981E - Turtle and Intersected Segments

We are given a set of segments on the number line. Each segment also carries a value $ai$. Two segments are considered related if their intervals overlap at least at one point, including touching at endpoints.

codeforcescompetitive-programmingdata-structuresdsugraphsgreedy
CF 1981C - Turtle and an Incomplete Sequence

We are given a sequence of positive integers where some elements have gone missing and are represented by -1. The original sequence had a special property: for every consecutive pair of numbers, either the first number is the floor of half of the second, or the second is the…

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsgreedyimplementationmath
CF 1981B - Turtle and an Infinite Sequence

We start with an infinite array where position $i$ initially contains the value $i$. So the array begins as a simple identity mapping: index equals value. Every second, all positions update simultaneously.

codeforcescompetitive-programmingbitmasksmath
CF 1981A - Turtle and Piggy Are Playing a Game

We are given a range of integers $[l, r]$. Turtle chooses a number $x$ from this range. After that, Piggy repeatedly divides $x$ by one of its divisors greater than or equal to $2$, earning one point for each division, until the number becomes $1$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1982E - Number of k-good subarrays

In this problem, we are given an array consisting of consecutive integers starting from zero. A subarray is considered k-good if every element within it has no more than k ones in its binary representation.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdivide-and-conquerdpmathmeet-in-the-middle
CF 1982F - Sorting Problem Again

We are given an array that changes over time through point updates. After each change, we must answer a structural question about the array: what is the shortest contiguous segment such that, if we sort only that segment, the entire array becomes sorted in non-decreasing order.

codeforcescompetitive-programmingbinary-searchdata-structuressortings
CF 1982D - Beauty of the mountains

We are given a grid of numbers representing mountain heights, together with a second grid that splits each cell into one of two groups. One group is marked as snowy-capped, the other is non-snowy.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmathnumber-theory
CF 1982B - Collatz Conjecture

We are asked to simulate a process on a number $x$ using another number $y$ and repeating it $k$ times. Each operation consists of two steps performed in order: first, increment $x$ by one, and second, divide $x$ by $y$ as many times as possible while $x$ remains divisible by…

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 1982A - Soccer

In this problem, we are given a soccer game scenario where Dima remembers two scores: one just before he got distracted and another when he returned. Each score consists of the goals of the two teams. The game progresses one goal at a time for either team.

codeforcescompetitive-programminggreedyimplementationmathsortings
CF 1982C - Boring Day

We are asked to simulate a game with a deck of cards arranged in a specific order. Each card has a positive integer on it.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedytwo-pointers
Kvant Math Problem 906

Consider the equation

kvantmathematicsolympiad
CF 1983G - Your Loss

We are given a tree of n nodes where each node has an associated integer value. The problem asks us to process multiple queries where each query specifies two nodes, x and y.

codeforcescompetitive-programmingbitmasksbrute-forcedptrees
CF 1983E - I Love Balls

There are two kinds of balls. The first k balls are special, the remaining n-k are ordinary. Every ball has a value. The balls are removed one by one in a uniformly random order. The current player takes the chosen ball and adds its value to their score.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 1983B - Corner Twist

We are given two grids, a and b, each of size n by m. Every cell in the grids contains a value from 0 to 2. Our goal is to transform grid a into grid b using a specific operation any number of times.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
Kvant Math Problem 894

The previous proof contains critical errors in both parts.

kvantmathematicsolympiad
CF 1983F - array-value

We are given an array and we look at every possible contiguous subarray of length at least two. For each subarray, we compute a value defined as the smallest XOR among all pairs of indices inside that subarray.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresgreedytwo-pointers
CF 1983D - Swap Dilemma

We are given two arrays of the same length, and each array is a permutation-like structure in the sense that all values inside each array are distinct.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdivide-and-conquergreedymathsortings
CF 1983C - Have Your Cake and Eat It Too

We are asked to split a linear cake of n pieces among Alice, Bob, and Charlie. Each person values each piece differently, and the total value of all pieces is the same for everyone.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyimplementation
Kvant Math Problem 944

The figure is the regular hexagon of side length $2$ subdivided into $24$ congruent equilateral triangles.

kvantmathematicsolympiad
CF 1983A - Array Divisibility

We are asked to construct an array of positive integers for each test case such that a family of divisibility conditions is satisfied simultaneously for every possible value of a parameter $k$ from 1 to $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1984E - Shuffle

We are given a tree with n nodes, and we can perform a single “shuffle” operation on it. The shuffle consists of picking any node as the new root, removing it from the tree, recursively shuffling each resulting subtree, and then attaching all the shuffled subtree roots back…

codeforcescompetitive-programmingdpgreedytrees
CF 1984H - Tower Capturing

We are given a set of $n$ towers located at distinct points in the plane, with the guarantee that no three towers are collinear and no four towers lie on the same circle. You initially control two of these towers. The goal is to "capture" all towers by a series of operations.

codeforcescompetitive-programmingcombinatoricsdpgeometry
CF 1984G - Magic Trick II

We are given a permutation of numbers from 1 to n. The task is to sort this permutation using a special operation that allows moving a continuous subarray of length k to any position in the array.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 1984F - Reconstruction

We are given a hidden integer array a of length n, where each element must stay within the range [-m, m]. We never see a, but instead we are given a sequence of constraints that describe either prefix sums or suffix sums of this array.

codeforcescompetitive-programmingbrute-forcedpmath
CF 1984C2 - Magnitude (Hard Version)

We process the array from left to right while maintaining a value c, initially 0. For every element a[i], we have two choices. We may replace c with c + a[i], or replace it with Among all possible procedures, let k be the largest final value that can be achieved.

codeforcescompetitive-programmingcombinatoricsdpgreedymath
CF 1984D - ''a'' String Problem

We are asked to find the number of nonempty strings $t neq "a"$ such that a given string $s$ can be split into pieces where each piece is either $t$ or the single character "a", with the additional constraint that at least one piece must equal $t$.

codeforcescompetitive-programmingbrute-forcehashingimplementationmathstring-suffix-structuresstrings
CF 1984A - Strange Splitting

Codeforces 1984A: Strange Splitting

codeforcescompetitive-programmingconstructive-algorithms
CF 1984C1 - Magnitude (Easy Version)

We are processing a sequence of numbers while maintaining a running value that starts at zero. At each position, we must decide between two actions: either add the current number directly, or add it and then take the absolute value of the result.

codeforcescompetitive-programmingdpgreedymath
CF 1984B - Large Addition

We are given a number $x$, and we want to decide whether it can be expressed as the sum of two positive integers that satisfy a very specific digit restriction. Each of the two addends must have all digits in the range 5 to 9, and both numbers must have the same number of digits.

codeforcescompetitive-programmingimplementationmath
CF 1985H1 - Maximize the Largest Component (Easy Version)

We are given a grid consisting of n rows and m columns, where each cell is either empty ('.') or filled (''). A connected component of filled cells is a set of '' tiles where you can move between any two tiles by only traveling along adjacent tiles sharing a side.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardsugraphsimplementation
Kvant Math Problem 885

The quantity $q(n)$ equals the sum, over all partitions $\lambda$ of $n$, of the number of distinct values appearing among the parts of $\lambda$.

kvantmathematicsolympiad
CF 1985H2 - Maximize the Largest Component (Hard Version)

We are given a grid of size $n times m$ where each cell is either empty ('.') or filled (''). Connected components of '' are sets of cells that can reach each other by moving up, down, left, or right.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsuimplementation
CF 1985G - D-Function

The problem asks us to count numbers $n$ in a given range such that multiplying $n$ by an integer $k$ scales the sum of digits by exactly $k$. Formally, if $D(n)$ is the sum of digits of $n$, we want all $n$ in $[10^l, 10^r)$ satisfying $D(k cdot n) = k cdot D(n)$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1985F - Final Boss

We are asked to simulate a battle with a single boss that has a starting health h. The player has n different attacks. Each attack i deals ai damage and has a cooldown ci, meaning that once used, that attack cannot be reused for ci turns.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 1985E - Secret Box

We are asked to place a small box with integer side lengths inside a larger box in 3D space. The small box must have a specific volume $k$ and must align with the axes, with all corners at integer coordinates.

codeforcescompetitive-programmingbrute-forcecombinatoricsmath
Kvant Math Problem 884

The reviewer correctly identified a critical error.

kvantmathematicsolympiad
CF 1985D - Manhattan Circle

We are given a grid made of dots and hashes. Somewhere in this grid there is a shape formed by all cells whose Manhattan distance to a hidden center is strictly less than a radius. This creates a diamond-shaped region aligned with the grid axes.

codeforcescompetitive-programmingimplementationmath
CF 1985C - Good Prefixes

The problem asks us to analyze prefixes of an integer array and determine which prefixes are "good" according to a specific rule. A prefix of length $i$ is considered good if there exists an element in the prefix equal to the sum of all other elements.

codeforcescompetitive-programminggreedy
CF 1985A - Creating Words

We are given two strings, each exactly three letters long, and our task is to swap their first characters. For each test case, the input provides two strings, and the output should reflect the two new strings formed after the swap.

codeforcescompetitive-programmingimplementationstrings
CF 1985B - Maximum Multiple Sum

We are asked to select a number $x$ between 2 and $n$ inclusive such that the sum of all multiples of $x$ that do not exceed $n$ is maximized. For example, if $n = 15$ and we pick $x = 2$, the multiples are 2, 4, 6, 8, 10, 12, 14, and their sum is 56.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1986G2 - Permutation Problem (Hard Version)

We are given a permutation of integers from 1 to $n$, and we are asked to count how many pairs of indices $(i, j)$ satisfy $i < j$ and $pi cdot pj$ divisible by $i cdot j$.

codeforcescompetitive-programmingbrute-forcedata-structureshashingmathnumber-theory
CF 1986G1 - Permutation Problem (Simple Version)

We are given a permutation of length $n$, meaning every number from $1$ to $n$ appears exactly once, but in some shuffled order.

codeforcescompetitive-programmingbinary-searchbrute-forcecombinatoricsdata-structuresmathnumber-theory
CF 1986F - Non-academic Problem

We are given a connected undirected graph. Between any two vertices, we can ask whether there is a path connecting them. If a path exists, that pair contributes to the final answer.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 1986D - Mathematical Problem

We are given a string of digits, and our goal is to insert exactly $n-2$ arithmetic symbols, either plus or multiplication, between digits to form a valid arithmetic expression.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationmathtwo-pointers
CF 1986E - Beautiful Array

We are given an integer array and a fixed increment value $k$. We are allowed to reorder the array arbitrarily before doing anything else, and then repeatedly apply an operation that increases a single chosen element by exactly $k$.

codeforcescompetitive-programminggreedymathnumber-theorysortings
Kvant Math Problem 875

Let

kvantmathematicsolympiad
CF 1986B - Matrix Stabilization

The problem asks us to stabilize a matrix by repeatedly decreasing “peaks,” which are cells strictly larger than all their neighbors. The matrix is given as an $n times m$ grid of integers.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedysortings
CF 1986A - X Axis

We are given three integer points on a one-dimensional number line, specifically the X axis. The task is to find a single integer coordinate such that the sum of the distances from this chosen point to the three given points is minimized.

codeforcescompetitive-programmingbrute-forcegeometrymathsortings
CF 1986C - Update Queries

We are given a starting string and a multiset of update operations. Each update consists of a position in the string and a lowercase letter.

codeforcescompetitive-programmingdata-structuresgreedysortings
Kvant Math Problem 853

A square $ABCD$ rotates about its fixed center $O$, while a fixed line $l$ is taken as the $x$-axis.

kvantmathematicsolympiad
Kvant Math Problem 836

The coordinate setup in the proposed solution is correct and can be carried through to completion.

kvantmathematicsolympiad
CF 1987E - Wonderful Tree!

We are given a rooted tree with integer values assigned to each node. The tree is rooted at vertex 1. A tree is considered wonderful if, for every non-leaf vertex, its value is at most the sum of the values of its immediate children.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardsugreedytrees
CF 1987C - Basil's Garden

We are asked to simulate a garden of flowers arranged in a line, where each flower has an initial height. The wind blows from the left every second and decreases the height of some flowers according to a strict rule: a flower will shrink if it is the last flower in the line or…

codeforcescompetitive-programmingdpgreedy
CF 1988F - Heartbeat

We are asked to sum over all permutations of numbers from 1 to $n$, a cost function that depends on three characteristics of each permutation: the number of prefix maximums, the number of suffix maximums, and the number of ascents.

codeforcescompetitive-programmingcombinatoricsdpfftmath