brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1774B - Coloring

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1774A - Add Plus Minus Sign

We are given a binary string, a sequence of 0 and 1, and we want to insert either + or - between each pair of consecutive digits so that the absolute value of the resulting arithmetic expression is minimized.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1775E - The Human Equation

We are given an array of integers and a peculiar operation that allows us to select any subsequence and adjust its elements in an alternating fashion: either adding 1 to numbers at odd positions and subtracting 1 from numbers at even positions, or the reverse.

codeforcescompetitive-programminggreedyimplementation
CF 1775C - Interesting Sequence

We are asked to find the smallest integer $m ge n$ such that the bitwise AND of all numbers from $n$ to $m$ equals a given number $x$. Formally, we want $n & (n+1) & dots & m = x$.

codeforcescompetitive-programmingbitmasksmath
CF 1775F - Laboratory on Pluto

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedymath
CF 1775D - Friendly Spiders

We are given a colony of spiders on Mars, each identified by the number of legs it has. Two spiders are considered friends if the greatest common divisor of their leg counts is greater than one.

codeforcescompetitive-programmingdfs-and-similargraphsmathnumber-theoryshortest-paths
CF 1775A1 - Gardener and the Capybaras (easy version)

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementation
CF 1775B - Gardener and the Array

We are given an array of integers where each integer is specified by the set of its 1-bits rather than its numeric value. The task is to determine whether there exist two distinct subsequences of the array that produce the same bitwise OR.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1775A2 - Gardener and the Capybaras (hard version)

The problem gives us a string of letters 'a' and 'b', which represents three capybara names concatenated together.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1776M - Parmigiana With Seafood

This is a Type B (prove inequality) problem, not Type C. The task is to prove that $$frac1{a^3(b+c)}+frac1{b^3(c+a)}+frac1{c^3(a+b)}ge frac32$$ for all positive $a,b,c$ satisfying $abc=1$.

codeforcescompetitive-programmingbinary-searchdpgreedytrees
CF 1776L - Controllers

We are asked to determine whether a player can reach exactly zero score after a sequence of game rounds, given a controller with two buttons labeled with arbitrary positive integers.

codeforcescompetitive-programmingbinary-searchmath
CF 1776N - Count Permutations

We are asked to count the number of permutations of the numbers from 1 to $n$ that satisfy a chain of inequalities described by a string of length $n-1$. Each character of the string is either < or .

codeforcescompetitive-programmingmath
CF 1776K - Uniform Chemistry

Each researcher starts with a chemical labeled by an integer between $1$ and $n-1$. Every year they upgrade their current chemical: if someone currently holds value $a$, they replace it with a uniformly random integer from the interval $(a, n]$.

codeforcescompetitive-programmingdpmath
CF 1776J - Italian Data Centers

Codeforces 1776J: Italian Data Centers

codeforcescompetitive-programminggraphsshortest-paths
CF 1776H - Beppa and SwerChat

The list shown by SwerChat is ordered by recency. The member who was online most recently appears first, the second most recent appears second, and so on. At 9:00, Beppa records an ordering a. At 22:00, she records another ordering b.

codeforcescompetitive-programmingtwo-pointers
CF 1776I - Spinach Pizza

We are given a strictly convex polygon with labeled vertices in counterclockwise order. Each move consists of choosing one currently unused vertex.

codeforcescompetitive-programminggamesgeometrygreedyinteractive
CF 1776F - Train Splitting

We are given a connected undirected graph. Every edge must be assigned to a company. Suppose company c owns all edges colored c. The coloring must satisfy two conditions. The first condition says that no single company is allowed to own a connected spanning network.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 1776G - Another Wine Tasting Event

We are given a binary string of length $2n-1$, where each position represents a bottle of wine, either white or red. From this fixed sequence, we need to assign $n$ critics to $n$ distinct segments of the array.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathstrings
CF 1776E - Crossing the Railways

We are asked to simulate a person, Isona, crossing a set of parallel railway tracks from one platform to another, while avoiding trains. The crossing is straight and perpendicular to the railways.

codeforcescompetitive-programmingdata-structuresdp
CF 1776D - Teamwork

We are asked to schedule a team of three people to solve a set of problems with three difficulty levels: easy, medium, and hard. Each problem has a fixed duration depending on its difficulty: easy takes 2 units of time, medium 3 units, and hard 4 units.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1776A - Walking Boy

The task asks us to determine whether it is possible for the judge to have walked Boy, her dog, at least twice during a single day given a timeline of messages. Each walk takes exactly 120 minutes, cannot overlap another walk, and the judge never sends messages during a walk.

codeforcescompetitive-programminggreedy
CF 1776B - Vittorio Plays with LEGO Bricks

We are asked to place a set of LEGO Duplo bricks on a 1D line along the x-axis, with the constraint that each brick occupies a 2×2 square on the ground and has height 1.

codeforcescompetitive-programmingdpgeometry
CF 1776C - Library game

We are playing a sequential game on a line of labeled sections, each section representing a distinct subject. Each day, one of two players chooses a contiguous interval of sections, constrained by a fixed length coming from a multiset of available “passes”.

codeforcescompetitive-programminggamesgreedyinteractivesortings
Kvant Math Problem 2882

The game begins with $1000$ heaps containing $1,2,3,\dots,1000$ matches respectively.

kvantmathematicsolympiad
CF 1777E - Edge Reverse

The problem gives us a weighted directed graph and asks us to make it "strongly reachable" from some node by optionally reversing edges. The cost of a reversal is the weight of the heaviest edge we choose to reverse, and our goal is to minimize this maximum.

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphstrees
CF 1777F - Comfortably Numb

We are given a sequence of non-negative integers and asked to examine every contiguous segment. For each segment, we compute two values: the bitwise XOR of all elements in the segment, and the maximum element in that same segment.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerstringstrees
CF 1777C - Quiz Master

We are asked to select a subset of students from a school to form a quiz team. Each student has a smartness value, and each quiz topic requires at least one team member whose smartness is divisible by the topic number.

codeforcescompetitive-programmingbinary-searchmathnumber-theorysortingstwo-pointers
CF 1777D - Score of a Tree

We are given a rooted tree with n nodes. Each node initially holds a value of either 0 or 1. The evolution of values in the tree is defined by a simple rule: at each integer time t 0, every non-leaf node updates its value to the XOR of the values of its children from the…

codeforcescompetitive-programmingbitmaskscombinatoricsdfs-and-similardpmathprobabilitiestrees
CF 1777B - Emordnilap

We are asked to compute a sum over all permutations of size $n$, where each permutation contributes the number of inversions in a specific array derived from it.

codeforcescompetitive-programmingcombinatoricsgreedymath
CF 1777A - Everybody Likes Good Arrays!

We are asked to transform an array of integers into a “good array,” which is defined as an array where no two consecutive elements share the same parity. Parity simply means whether a number is odd or even.

codeforcescompetitive-programminggreedymath
CF 1778E - The Tree Has Fallen!

We are given a tree with n nodes, where each node has an integer value written on it. Bob can pick a root r for the tree, which establishes parent-child relationships. Then Alice picks a node v, and Bob can choose any subset of nodes from the subtree rooted at v.

codeforcescompetitive-programmingbitmasksdfs-and-similarmathtrees
CF 1778F - Maximizing Root

We are asked to maximize the value of the root of a tree after performing at most $k$ operations. Each operation allows us to pick a vertex $v$ that has not been selected before, choose a number $x$ that divides all values in $v$'s subtree, and multiply every value in that…

codeforcescompetitive-programmingdfs-and-similardpgraphsmathnumber-theorytrees
CF 1778A - Flip Flop Sum

We are given an array consisting only of 1s and -1s. The task is to perform exactly one operation: select two consecutive elements and flip their signs. After doing this, we want to maximize the sum of all array elements.

codeforcescompetitive-programminggreedyimplementation
CF 1778D - Flexible String Revisit

Two binary strings of equal length evolve over time, but only one of them changes. At every move, we pick a position uniformly among all indices and flip the bit of the first string at that position. The second string is fixed.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1778B - The Forbidden Permutation

We are given a permutation p of the numbers 1...n. Another array a contains m distinct values that all appear in the permutation. For every value, we care only about its position inside the permutation. Let pos[x] be the index of value x in p.

codeforcescompetitive-programminggreedymath
CF 1778C - Flexible String

We are given two equal-length strings, and we are allowed to modify the first string in a very specific way. Each time we change a character in the first string, the original character at that position gets “recorded” into a special set.

codeforcescompetitive-programmingbitmasksbrute-forcestrings
Kvant Math Problem 2883

The previous solution attempted to prove nonexistence by separating cases according to the prime factorization of $n$.

kvantmathematicsolympiad
CF 1779G - The Game of the Century

The village is represented as a triangular grid of intersections. Each side of the triangle has length $n$, and the interior is subdivided into $n^2$ smaller equilateral triangles. The roads of the village run along the sides of these triangles and are one-way.

codeforcescompetitive-programmingconstructive-algorithmsgraphsshortest-paths
CF 1779E - Anya's Simultaneous Exhibition

We are asked to identify candidate masters among a group of chess players where the outcome of any head-to-head match is deterministic but may be non-transitive. That means some cycles can exist, such as player A beating B, B beating C, and C beating A.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyinteractivesortings
CF 1779H - Olympic Team Building

We are given a set of $n$ players, where $n$ is a power of two, and each player has a fixed positive strength. A sequence of elimination rounds is played. In each round, the current set of players is split into two equal groups.

codeforcescompetitive-programmingbrute-forcemeet-in-the-middle
CF 1779F - Xorcerer's Stones

We are given a rooted tree where each node stores a small integer value. A single operation selects a node and replaces every value in its subtree with the XOR of all values currently inside that subtree. After this assignment, every node in that subtree becomes identical.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdptrees
Kvant Math Problem 2884

The task is to determine the smallest integer $k$ such that, after adaptive subset queries with a binary oracle that may err but never on two consecutive days, the Wizard can always guarantee that at…

kvantmathematicsolympiad
CF 1779D - Boris and His Amazing Haircut

We are asked to transform Boris's current hairstyle into a desired one using a limited set of razors, each of which can cut hair down to a fixed length over any contiguous segment.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpdsugreedysortings
CF 1779C - Least Prefix Sum

We are given an array of integers, and Baltic wants a specific prefix sum-the sum of the first m elements-to be the smallest among all prefix sums of the array. We are allowed to flip the sign of any element any number of times.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1779A - Hall of Fame

Thalia has a line of trophies, each with a lamp that can shine either to the left or to the right. The lamp at position i illuminates all trophies strictly in the direction it points, excluding itself.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1779B - MKnez's ConstructiveForces Task

This is a Type B problem: prove impossibility. The solution correctly identifies that the task is to show that no plane can cut a regular $n$-gonal pyramid into a regular $(n+1)$-gon when $n ge 5$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1780D - Bit Guessing Game

The problem presents a game where we must determine a hidden integer n using only the number of set bits (1s) in its binary representation. Initially, we know how many 1s n has. We can subtract any positive integer x from n as long as it does not exceed n.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 1780G - Delicious Dessert

We are given a string s of length n representing Tonio's dessert recipe. A substring of s is called delicious if the number of times it appears in s is divisible by its own length. The task is to count all delicious substrings of s, counting multiple occurrences separately.

codeforcescompetitive-programmingbinary-searchdsuhashingmathnumber-theorystring-suffix-structures
CF 1780F - Three Chairs

We are asked to select three friends from a group of $n$ friends, each with a unique height, such that the smallest and largest heights among the chosen three are coprime. The input gives $n$ followed by an array of $n$ distinct integers representing the heights.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdata-structuresdpnumber-theorysortings
CF 1780E - Josuke and Complete Graph

Working

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresmathnumber-theory
CF 1780A - Hayato and School

We are asked to find, in an array of integers, three distinct elements whose sum is odd. The input consists of multiple test cases, each providing the array. The output must indicate whether such a triple exists, and if it does, provide any valid set of three indices.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1780B - GCD Partition

We are given an array of positive integers. Our task is to split this array into at least two contiguous subsegments, compute the sum of each subsegment, and then take the greatest common divisor (GCD) of these sums.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1781G - Diverse Coloring

I see exactly where prior solutions fail: the minimal cable along the walls and ceiling/floor is not simply the Manhattan distance in x + y + h, because the cable can wrap around walls, reducing the total distance in x or y by traveling along the opposite wall.

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 1781H2 - Window Signals (hard version)

We are working on a grid of size $h times w$, where each cell represents a window that can either be lit or dark. A configuration is simply a subset of cells chosen as “on”, with the restriction that at most two specific cells are forbidden from being used.

codeforcescompetitive-programming
CF 1781H1 - Window Signals (easy version)

We are given a building with $h$ floors and $w$ windows on each floor, forming a grid of $h times w$. Every window can be either on or off, except for up to two broken windows that are permanently off.

codeforcescompetitive-programming
CF 1781F - Bracket Insertion

We are asked to calculate the probability that a bracket sequence formed by repeated random insertions ends up being regular. The process starts with an empty string and runs for n steps. In each step, a new two-character string is inserted at a random position.

codeforcescompetitive-programmingcombinatoricsdpmathtrees
Kvant Math Problem 2878

This is a **Type B (prove)** problem.

kvantmathematicsolympiad
CF 1781B - Going to the Cinema

Each person has a threshold value $ai$. Their decision is completely determined by the final number of people attending the cinema. Suppose exactly $k$ people go.

codeforcescompetitive-programmingbrute-forcegreedysortings
CF 1781D - Many Perfect Squares

We are allowed to choose a shift value $x$, and this shift transforms every number in a fixed set by adding $x$. After shifting, we inspect how many of the resulting numbers become perfect squares.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1781E - Rectangle Shrinking

We are working on a very thin grid: only two rows, but an extremely large number of columns. Each input rectangle occupies some contiguous segment of columns and spans either row 1, row 2, or both.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedyimplementationtwo-pointers
Kvant Math Problem 2880

This is a Type B (prove) problem.

kvantmathematicsolympiad
CF 1781C - Equal Frequencies

We are asked to transform a given string into a "balanced" string, where every character that appears does so the same number of times. The transformation should change as few positions as possible.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationsortingsstrings
CF 1781A - Parallel Projection

We are working inside a rectangular room shaped like a box. A point on the floor marks where the laptop sits, and a point directly above on the ceiling marks where the projector hangs.

codeforcescompetitive-programminggeometrymath
CF 1783G - Weighed Tree Radius

We are given a tree with $n$ vertices, where each vertex has an initial weight $ai$. Distances between vertices are measured in the usual unweighted tree sense (number of edges along the path), but we define a weighted distance from vertex $v$ to vertex $u$ as $wv(u) = dv(u) +…

codeforcescompetitive-programmingdata-structuresdivide-and-conquerimplementationtrees
CF 1783D - Different Arrays

We start with a fixed integer array. The process described in the problem does not allow arbitrary modifications.

codeforcescompetitive-programmingbrute-forcedpimplementation
Kvant Math Problem 2877

The flaw in the previous solution is the assumption that Wolf must win on every graph, and that showing a single losing graph is sufficient to refute his strategy.

kvantmathematicsolympiad
CF 1783F - Double Sort II

We are given two rows of numbers, each row being a permutation of 1..n. Think of them as two parallel arrays where every value from 1 to n appears exactly once in each row. The only allowed move is driven by a value i, not by a position.

codeforcescompetitive-programmingdfs-and-similarflowsgraph-matchingsgraphs
CF 1783E - Game of the Year

For each boss, Monocarp would kill it on his a[i]-th personal attempt, while Polycarp would kill it on his b[i]-th personal attempt. The fight is divided into blocks of size k. Monocarp performs k attempts, then Polycarp performs k attempts, then Monocarp again, and so on.

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
Kvant Math Problem 2873

Something went wrong.

kvantmathematicsolympiad
CF 1783B - Matrix of Differences

We are asked to construct an $n times n$ grid filled with the integers from $1$ to $n^2$ exactly once. Once the grid is built, we look at every pair of cells that share a side and compute the absolute difference of their values.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1783C - Yet Another Tournament

We are in a round-robin tournament with $n+1$ participants: you and $n$ opponents labeled from 1 to $n$. Every opponent pair plays exactly once, and stronger opponents always beat weaker ones: opponent $i$ beats $j$ if $i j$. Against you, the situation is different.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1783A - Make it Beautiful

We are given an array of integers sorted in non-decreasing order, and we need to rearrange its elements so that no element equals the sum of all previous elements. If such a rearrangement is impossible, we must report it.

codeforcescompetitive-programmingconstructive-algorithmsmathsortings
CF 1784E - Infinite Game

We are given a short string consisting of characters that can be interpreted as decisions in a repeated competitive process. Each character represents a round outcome between two players, and the string is repeated infinitely to generate an endless sequence of rounds.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgamesprobabilities
CF 1784F - Minimums or Medians

We are given the set of consecutive integers from 1 to 2n. Vika performs exactly k operations on this set. Each operation consists of either removing the two smallest integers or removing the two middle integers, which are the two integers at positions n and n+1 if the set is…

codeforcescompetitive-programming
CF 1784D - Wooden Spoon

We are asked to count, for each player in a single-elimination tournament of size $2^n$, the number of ways they can end up with a "Wooden Spoon." The tournament is deterministic: whenever two players meet, the one with the smaller number always wins.

codeforcescompetitive-programmingcombinatoricsdp
CF 1784A - Monsters (easy version)

We are given several independent scenarios. In each scenario, there are $n$ monsters arranged conceptually in a line, and each monster has some integer health value. A monster disappears once its health reaches zero. We can perform two kinds of actions.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1784C - Monsters (hard version)

We are asked to find the minimum number of single-target damage spells needed to kill monsters in a game, where a powerful area-of-effect spell can also be cast once.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1784B - Letter Exchange

Each person starts with exactly three letters chosen from w, i, and n. Across all people combined, there are exactly m copies of each letter, so globally the supply is already balanced. The only issue is that the letters are distributed unevenly among individuals.

codeforcescompetitive-programmingconstructive-algorithms
CF 1786A2 - Alternating Deck (hard version)

We have a deck of n cards arranged so that the colors strictly alternate, starting with white. Alice deals these cards in increasing batch sizes: first one card to herself, then two cards to Bob, three cards to Bob, four cards to Alice, five to Alice, six to Bob, seven to Bob…

codeforcescompetitive-programmingimplementation
CF 1786B - Cake Assembly Line

We are given two ordered systems on a number line. One system represents cakes, each occupying a fixed interval centered at a given position, and the other represents chocolate dispensers, each also producing a fixed interval of coverage.

codeforcescompetitive-programmingbrute-forcesortings
CF 1786A1 - Non-alternating Deck (easy version)

We are simulating a very specific dealing process from a deck of identical cards. Cards are taken from the top of the deck in increasing batch sizes. On the first move, 1 card is dealt, on the second move 2 cards, on the third move 3 cards, and so on.

codeforcescompetitive-programmingimplementation
CF 1787I - Treasure Hunt

We are asked to calculate a sum over all non-empty contiguous subarrays of a given sequence. For each subarray, we define a "beauty value" that depends on choosing two segments: the prefix of some length q and another subsegment bs..bt that may overlap with the prefix.

codeforcescompetitive-programmingdata-structuresdivide-and-conquertwo-pointers
CF 1787H - Codeforces Scoreboard

I can't reliably produce a complete editorial and accepted implementation for Codeforces 1787H from the problem statement alone. This is a 3300-rated problem whose accepted solution uses a fairly intricate convex-DP / slope-trick optimization.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgeometry
CF 1787G - Colorful Tree Again

We are given a tree of n nodes, where each edge has a weight and a color. Initially, all nodes are unblocked. A path is considered good if it consists solely of edges of a single color, all edges of that color appear somewhere on the path, and all nodes on the path are unblocked.

codeforcescompetitive-programmingbrute-forcedata-structurestrees
CF 1787B - Number Factorization

The problem asks us to take an integer $n$ and factor it into a product of integers raised to positive powers, $n = prod ai^{pi}$, with the constraint that each $ai$ is composed of distinct prime numbers only.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1787F - Inverse Transformation

I’m sorry, but I can’t reliably produce a complete editorial and full accepted implementation for Codeforces 1787F from memory alone.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1787E - The Harmonization of XOR

We are given the consecutive integers from 1 to n, and we must split them into exactly k groups so that every number appears in exactly one group.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
Kvant Math Problem 2879

Consider small natural numbers $n$ and compute $S(n)$, $S(7n)$, and $S(9n)$.

kvantmathematicsolympiad
CF 1787D - Game on Axis

We are given an array of integers, each representing a "jump" value on points labeled from $1$ to $n$. Starting at position $1$, we move to the next position by adding the current value: if we are at $i$, we jump to $i + ai$.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardsugraphsimplementation
CF 1787A - Exponential Equation

We are asked to find two integers $x$ and $y$ between 1 and $n$ inclusive such that the sum of $x^y cdot y$ and $y^x cdot x$ equals $n$. Conceptually, we are looking for a pair whose mixed exponential terms, weighted by the other number, add up exactly to $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1787C - Remove the Bracket

We are given an array $a$ and a value $s$. For every internal position $i$ with $2 le i le n-1$, we must split $ai$ into two non-negative parts: $$xi + yi = ai$$ The additional condition $$(xi-s)(yi-s)ge 0$$ means that both parts must lie on the same side of $s$.

codeforcescompetitive-programmingdpgreedymath
CF 1788F - XOR, Tree, and Queries

We have a tree with $n$ vertices and $n-1$ edges. We must assign a non-negative integer weight to every edge. Some constraints are given in the form $(u,v,x)$, meaning that the XOR of all edge weights along the unique path between $u$ and $v$ must equal $x$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdfs-and-similardsugraphsgreedyimplementationtrees
CF 1788E - Sum Over Zero

We are given an array of integers and want to choose several segments on it. Each chosen segment must have a non-negative sum, and no two chosen segments are allowed to overlap.

codeforcescompetitive-programmingdata-structuresdfs-and-similardp
CF 1788D - Moving Dots

We are given a set of $n$ distinct dots positioned on a number line. Each dot moves toward the nearest other dot, stopping when it meets another dot. If a dot has two equally close neighbors, it moves left. Once dots meet, they merge into a single stationary point.

codeforcescompetitive-programmingbinary-searchbrute-forcecombinatoricsmathtwo-pointers
CF 1788A - One and Two

We are given a sequence of numbers where each element is either 1 or 2. Our goal is to split the sequence into two contiguous parts such that the product of numbers in the first part equals the product of numbers in the second part.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1788C - Matching Numbers

The task asks us to pair up all integers from 1 to 2n into exactly n pairs, such that the sums of the pairs form a sequence of consecutive integers.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1789E - Serval and Music Game

We are given a strictly increasing sequence of positive integers, and the largest element of this sequence plays a special role. Let us call this largest value $S$. For every integer $x$ from $1$ to $S$, we derive two numbers: the floor and ceiling of $S/x$.

codeforcescompetitive-programmingbrute-forcedpimplementationmathnumber-theory
CF 1789F - Serval and Brain Power

We are asked to find the length of the longest "powerful" subsequence of a given string. A powerful string is one that can be obtained by repeating a smaller string at least twice. Formally, if some string $T'$ can be repeated $k ge 2$ times to form $T$, then $T$ is powerful.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedyimplementationstrings
CF 1789D - Serval and Shift-Shift-Shift

We are given two binary numbers a and b of length n, and we want to transform a into b using a series of XOR-shift operations.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsimplementation
CF 1789A - Serval and Mocha's Array

We are given several test cases, each consisting of a small array of positive integers. For each array, we are allowed to reorder its elements arbitrarily. After choosing an order, we inspect every prefix of length at least two and compute the gcd of that prefix.

codeforcescompetitive-programmingbrute-forcemathnumber-theory