brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1386C - Joker

Let $N = pq$ where $p equiv 3 pmod 8$ and $q equiv 7 pmod 8$. We first prove the claimed identity involving the Jacobi symbol.

codeforcescompetitive-programming*specialbitmasksdata-structuresdivide-and-conquerdsu
CF 1387B1 - Village (Minimum)

We are given a village consisting of N houses connected by N-1 roads in a tree structure, so every house is reachable from any other via exactly one simple path. Each house initially has one villager. The villagers want to move so that no one remains in their original house.

codeforcescompetitive-programming*specialdpgreedytrees
CF 1388B - Captain Flint and a Long Voyage

We need to construct an $n$-digit decimal number $x$. Take every digit of $x$, write its binary representation without leading zeroes, and concatenate those binary strings. The resulting binary string is called $k$. After that, the last $n$ bits of $k$ are removed.

codeforcescompetitive-programminggreedymath
CF 1389F - Bicolored Segments

We are given a set of segments on the number line, each colored either 1 or 2. A pair of segments is considered bad if they overlap or touch and have different colors. Our goal is to select as many segments as possible while avoiding any bad pair.

codeforcescompetitive-programmingdata-structuresdpgraph-matchingssortings
CF 1389B - Array Walk

We are asked to simulate a walk along an array of positive integers, starting at the first element. Each move can either go one step to the right, which is always allowed if we are not at the last element, or one step to the left, which can only be done if we are not at the…

codeforcescompetitive-programmingbrute-forcedpgreedy
CF 1391E - Pairs of Pairs

We are given a connected undirected graph, and the task is not to compute a classical graph property, but to construct one of two global structures that are guaranteed to exist. The first possible output is a simple path that visits at least half of the vertices.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedytrees
CF 1391C - Cyclic Permutations

We are given a permutation of numbers 1...n. From that permutation, a graph is constructed on the indices of the array. For every position i, we connect it to the nearest larger element on the left and the nearest larger element on the right, whenever such elements exist.

codeforcescompetitive-programmingcombinatoricsdpgraphsmath
CF 1392B - Omkar and Infinity Clock

I see exactly what went wrong. The logic we discussed is correct, but the Python solution produced no output because it used sys.stdout.write("n".join(ans)) without adding a final newline, and in some online judges this can result in an empty output if the buffer is not flushed.

codeforcescompetitive-programmingimplementationmath
CF 1392I - Kevin and Grid

Kevin is dropped into a rectangular grid where each row and column contributes a fixed amount of heat to each cell. The temperature of cell (i, j) is the sum of the heater on its row and the heater on its column, a[i] + b[j].

codeforcescompetitive-programmingfftgraphsmath
CF 1392H - ZS Shuffles Cards

Algorithm B is the binary gcd algorithm. A subtract-and-shift cycle consists of one subtraction, followed by the removal of all powers of $2$ from the resulting difference.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1392G - Omkar and Pies

We are given a very small binary “target state” of size $k le 20$, representing pies placed in fixed positions. We also have an initial configuration of those pies and a desired configuration.

codeforcescompetitive-programmingbitmasksdfs-and-similardpmathshortest-paths
CF 1392D - Omkar and Bed Wars

Each player sits on a circle and attacks exactly one of their two neighbors. We are given a circular string consisting of L and R. If player i attacks left, we write L. If they attack right, we write R.

codeforcescompetitive-programmingdpgreedy
CF 1392F - Omkar and Landslide

We are given a mountain represented as a strictly increasing sequence of heights, where each height corresponds to a meter along the slope. Omkar observes the mountain, and suddenly, a landslide occurs.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedymath
CF 1392E - Omkar and Duck

We are working with a small grid, at most 25 by 25, where a path is formed from the top-left cell to the bottom-right cell using only moves to the right or downward.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1392C - Omkar and Waterslide

We are given a sequence of heights arranged from left to right. The goal is to modify this sequence so that it becomes nondecreasing, meaning every element is at least as large as the one before it.

codeforcescompetitive-programminggreedyimplementation
CF 1392A - Omkar and Password

The proposed solution does not answer the exercise as stated. The exercise asks for values of $u$ and $v$ satisfying the prescribed binary-length conditions, $$lfloor lg u rfloor = m,qquad lfloor lg v rfloor = n,$$ such that Algorithm B requires exactly $m+1$ subtraction steps.

codeforcescompetitive-programminggreedymath
CF 1393C - Pinkie Pie Eats Patty-cakes

We are given a multiset of patty-cakes represented by integers. Equal integers mean equal fillings. We may choose any order in which to eat them. For every filling that appears multiple times, we can look at the distances between consecutive occurrences in the eating order.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1393E2 - Twilight and Ancient Scroll (harder version)

We are given a sequence of words that are supposed to represent an already sorted “original scroll”. The original property is that if you read the words from top to bottom, they are in non-decreasing lexicographic order.

codeforcescompetitive-programmingdphashingimplementationstring-suffix-structuresstringstwo-pointers
CF 1393B - Applejack and Storages

Applejack wants to build two storages using planks from a storehouse: one square and one rectangle. Each side of a storage uses exactly one plank, so a square requires four planks of the same length and a rectangle requires two pairs of equal-length planks.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1393E1 - Twilight and Ancient Scroll (easier version)

We are given a sequence of words that is supposed to come from an originally sorted list, where the original list was non-decreasing in lexicographic order.

codeforcescompetitive-programmingdphashingimplementationstring-suffix-structuresstrings
CF 1393D - Rarity and New Dress

We are given a grid of characters where each cell represents a colored tile. From this grid we want to count how many “valid dress patterns” exist.

codeforcescompetitive-programmingdfs-and-similardpimplementationshortest-paths
CF 1393A - Rainbow Dash, Fluttershy and Chess Coloring

We are given a square grid of size $n times n$. The goal is to completely cover every cell with two colors in a chessboard pattern, meaning adjacent cells must always have opposite colors.

codeforcescompetitive-programminggreedymath
CF 1394B - Boboniu Walks on Graph

Ah, now the bug is about the order in which the pairs are generated. The input is: and the expected output is: The previous code produced the pairs row-major from (1,1) to (n,m), which is why it printed: That is lexicographical order by row then column, but the problem wants a…

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphshashing
CF 1394E - Boboniu and Banknote Collection

We are given a sequence that grows one element at a time, and after each prefix we want to know how “deeply foldable” it is under a very specific rule. A folding is represented by assigning each position a direction, either +1 or -1.

codeforcescompetitive-programmingstrings
CF 1394A - Boboniu Chats with Du

We are given a sequence of “fun values” representing how entertaining Du’s messages are on each day. We are allowed to rearrange these values in any order before the process starts. After fixing an order, the days proceed from left to right.

codeforcescompetitive-programmingdpgreedysortingstwo-pointers
CF 1394D - Boboniu and Jianghu

We are given a tree of n mountains, connected by n-1 roads so that every mountain is reachable from any other. Each mountain has a height hi and a tiredness ti.

codeforcescompetitive-programmingdpgreedysortingstrees
CF 1394C - Boboniu and String

We are given several strings composed only of two characters, which we can think of as two symbols, say B and N. The task is to choose another string t over the same alphabet such that all given strings can be transformed into something “equivalent” to t under a specific…

codeforcescompetitive-programmingbinary-searchgeometryternary-search
CF 1395B - Boboniu Plays Chess

Thanks. I can see exactly why the program fails. The traceback shows: Looking at the input: The program immediately tries to unpack two integers from the first line after reading the number of test cases, but the actual input format is clearly different: it starts with a…

codeforcescompetitive-programmingconstructive-algorithms
CF 1395A - Boboniu Likes to Color Balls

We are given counts of four types of balls: red, green, blue, and white. The only allowed operation takes one red, one green, and one blue ball and converts all three into white balls. We may apply this operation any number of times.

codeforcescompetitive-programmingbrute-forcemath
CF 1395C - Boboniu and Bit Operations

We are given two small arrays of integers. For every element in the first array, we must pick one element from the second array and combine them using bitwise AND. This produces a new value for each position in the first array.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedy
CF 1396B - Stoned Game

The traceback tells us exactly what happened: The code is trying to read an edge of a tree as two integers u v. But the actual input is: Let's trace it: First test case: Then the next line is which is an array of length 7.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgamesgreedy
CF 1396A - Multiples of Length

Thank you for clarifying. Now I can carefully trace the bug. The input is: Expected output: But your current code outputs: Your code probably does something like: But the expected outputs (3, 6, 1) do not match counting '1's directly: - "120" → output 3 (not 1) - "11011" →…

codeforcescompetitive-programmingconstructive-algorithmsgreedynumber-theory
CF 1396E - Distance Matching

We are given a tree with an even number of nodes and an integer $k$. From this tree, we can construct a complete graph where each node represents a vertex from the tree and the weight of an edge between any two vertices is the distance between the corresponding nodes in the tree.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similartrees
CF 1396D - Rainbow Rectangles

We are given a set of colored points on a very large grid. Each point has integer coordinates and one of $k$ colors. We want to count how many axis-aligned integer rectangles we can choose such that the rectangle contains at least one point of every color.

codeforcescompetitive-programmingdata-structuressortingstwo-pointers
CF 1396C - Monster Invaders

We are asked to compute the minimum time for Ziota to clear all bosses in a sequence of game levels. Each level contains some number of normal monsters, each with 1 health point, and exactly one boss with 2 health points.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1397B - Power Sequence

We are given an array of positive integers and we are allowed to reorder it arbitrarily. After choosing an order, we want to transform the array into a very rigid pattern: the first element should be 1, the second should be some fixed number c, the third c squared, and so on…

codeforcescompetitive-programmingbrute-forcemathnumber-theorysortings
CF 1397A - Juggling Letters

We are given a set of strings, and we can move characters freely between any strings, including moving a character from a string back into itself. The goal is to determine if it is possible to rearrange all the characters so that every string ends up identical.

codeforcescompetitive-programminggreedystrings
CF 1398A - Bad Triangle

This failure is not caused by the algorithm at all. It is a pure syntax error in the test harness. The traceback says: So the string passed into run() is never closed.

codeforcescompetitive-programminggeometrymath
CF 1398G - Running Competition

We are asked to model a running stadium as a rectangle subdivided by vertical lines. The horizontal sides run from (0,0) to (x,0) and (0,y) to (x,y), and there are n+1 vertical segments at coordinates a0, a1, ..., an, which connect the top and bottom edges.

codeforcescompetitive-programmingbitmasksfftmathnumber-theory
CF 1398C - Good Subarrays

Ah! Now the problem is crystal clear. The error: tells us exactly what’s wrong: your code is assuming that every line after the header has 3 integers (u v w), but the actual input is inconsistent: - Some lines have 3 numbers (edges with weight: 1 3 100) - Some lines have only…

codeforcescompetitive-programmingdata-structuresdpmath
CF 1398F - Controversial Rounds

We are given a long sequence of match outcomes, where each position is either a win for Alice, a win for Bob, or unknown. The actual game is not just a flat sequence of independent results.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedytwo-pointers
CF 1398E - Two Types of Spells

Each update in this problem either adds or removes a spell from Polycarp’s arsenal. Every spell belongs to one of two classes. A fire spell contributes its raw value as damage when cast.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementationmathsortings
CF 1398D - Colored Rectangles

We are given three collections of sticks, grouped by color. Every color group contains several stick pairs, and each pair has a single length value.

codeforcescompetitive-programmingdpgreedysortings
CF 1398B - Substring Removal Game

The game operates on a binary string that can be thought of as a sequence of adjacent blocks of identical characters. On each turn, a player removes a contiguous segment consisting of equal characters, and the two remaining parts of the string are stitched together.

codeforcescompetitive-programminggamesgreedysortings
CF 1399E1 - Weights Division (easy version)

Thanks - now we can carefully diagnose this. The crash happens here: with the error: The input is: Breaking it down: - 3 → number of test cases T = 3 Test case 1: Test case 2: So clearly the input is hierarchical, not every line has the same number of numbers.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
CF 1399F - Yet Another Segments Subset

We are given a collection of segments on a number line, each defined by a left endpoint and a right endpoint. The task is to select the largest possible subset of these segments with a specific property: for any two segments in the subset, they must either be completely…

codeforcescompetitive-programmingdata-structuresdpgraphssortings
CF 1399B - Gifts Fixing

We are given n gifts, where each gift consists of a certain number of candies and a certain number of oranges. Each gift i has ai candies and bi oranges. Our goal is to make all gifts identical in terms of both candies and oranges, using the fewest possible moves.

codeforcescompetitive-programminggreedy
CF 1399E2 - Weights Division (hard version)

We are given a tree rooted at vertex 1, where each edge has a weight and an associated cost of either 1 or 2 coins.

codeforcescompetitive-programmingbinary-searchdfs-and-similargreedysortingstreestwo-pointers
Kvant Math Problem 1556

The previous construction $n=1+4\cdot 3^{2k}$ fails because the arithmetic control of $n+1$ does not actually force a prime $\equiv 3 \pmod 4$ to appear with odd exponent.

kvantmathematicsolympiad
CF 1399D - Binary String To Subsequences

We are given a binary string and we want to break it into several subsequences so that every character is used exactly once, and each subsequence alternates between 0 and 1. In other words, inside any chosen subsequence, no two adjacent chosen characters can be equal.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 1399A - Remove Smallest

We are asked to determine if we can reduce an array of positive integers to a single element using a specific operation: choose two distinct elements whose difference is at most one and remove the smaller of the two (or either if they are equal).

codeforcescompetitive-programminggreedysortings
CF 1399C - Boats Competition

We have a set of participants, each with a specific weight. The competition only allows two-person teams, and each team must have the same combined weight. Our goal is to form as many teams as possible for a given set of participants.

codeforcescompetitive-programmingbrute-forcegreedytwo-pointers
CF 1400E - Clear the Multiset

We are given a multiset of integers from 1 to n, where the count of integer i is ai. Our goal is to completely remove all elements from the multiset using two types of operations.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgreedy
CF 1400G - Mercenaries

Polycarp wants to select a subset of mercenaries from a pool of n individuals. Each mercenary has two constraints: the minimum and maximum size of the team they are willing to join, given by li and ri.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdpdsumathtwo-pointers
CF 1400F - x-prime Substrings

We are given a digit string and a small integer $x$. Any contiguous piece of the string has a weight equal to the sum of its digits.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpstring-suffix-structuresstrings
CF 1400D - Zigzags

We are given an array of integers and asked to count how many quadruples of indices $(i, j, k, l)$ satisfy both $i < j < k < l$ and $a[i] = a[k]$, $a[j] = a[l]$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdata-structuresmathtwo-pointers
CF 1400C - Binary String Reconstruction

We are given a binary string $s$ and a distance parameter $x$. There exists an unknown original binary string $w$ of the same length.

codeforcescompetitive-programming2-satbrute-forceconstructive-algorithmsgreedy
CF 1401C - Mere Array

We are given an array of positive integers. The allowed operation is a swap between two elements if the greatest common divisor (GCD) of those two elements equals the minimum element of the array.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theorysortings
CF 1401D - Maximum Distributed Tree

Got it. Let’s go careful step by step. The input is: - The first line 5 is the number of queries (n = 5). - Each of the next 5 lines contains 4 integers: a b c d. The expected output is: - Each output line corresponds to an input line. - Each output line has 4 integers.

codeforcescompetitive-programmingdfs-and-similardpgreedyimplementationmathnumber-theorysortingstrees
CF 1401F - Reverse and Swap

We are working with an array of length $2^n$, where $n$ can be up to 18, so the array can have up to $262{,}144$ elements. Queries modify the array or request the sum of subarrays. There are four types of modifications. The first directly replaces an element.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structures
CF 1401E - Divide Square

We are asked to compute the number of pieces a large square is divided into after drawing several horizontal and vertical line segments.

codeforcescompetitive-programmingdata-structuresgeometryimplementationsortings
CF 1401A - Distance and Axis

We are given a point $A$ placed on the integer number line at coordinate $n$. We are allowed to adjust this point one unit left or right per move.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1401B - Ternary Sequence

We are given two multisets of numbers, each number being only 0, 1, or 2. The size of both multisets is the same, because we are told the total counts in each sequence match. We are allowed to reorder both sequences arbitrarily, and then we pair elements position by position.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1402B - Roads

The crash happens immediately on this line: but the actual input begins with: So the first line contains three integers, not two.

codeforcescompetitive-programming*specialgeometrysortings
CF 1402A - Fancy Fence

We are given a fence composed of $N$ rectangular sections placed side by side. Each section $i$ has a width $wi$ and a height $hi$. Our task is to count all axis-aligned rectangles that can be formed entirely on top of these sections.

codeforcescompetitive-programming*specialdata-structuresdsuimplementationmathsortings
CF 1402C - Star Trek

We are given a tree of $N$ planets. Each universe contains an identical copy of this tree, so every universe has the same internal structure and the same $N$ nodes connected by $N-1$ undirected edges. There are $D+1$ universes indexed from $0$ to $D$.

codeforcescompetitive-programming*specialcombinatoricsdfs-and-similardpgamesgraphsmatricestrees
CF 1403B - Spring cleaning

We are given a tree with N nodes, connected by N-1 edges. Each node may be a leaf, defined as a node with exactly one edge. Cleaning the tree involves selecting two different leaves and marking all edges along the shortest path between them as cleaned.

codeforcescompetitive-programming*specialdata-structuresdfs-and-similargraphstrees
CF 1403C - Chess Rush

Let’s trace what the wrong behavior implies. Input: Grid: There are only 4 cells total. But the output is 9, which is suspiciously close to “counting something per cell plus neighbors” or “counting all 2x2 substructures / adjacency contributions”.

codeforcescompetitive-programming*specialcombinatoricsdpimplementationmath
CF 1403A - The Potion of Great Power

We have a dynamic friendship network among N shamans, each living at a specific altitude H[i]. Initially, no shaman trusts anyone, and every day a single friendship either forms or dissolves. Each shaman can trust at most D others at any time.

codeforcescompetitive-programming*special2-satbinary-searchdata-structuresgraphsinteractivesortingstwo-pointers
CF 1404E - Bricks

I see exactly what’s going wrong. The previous approach blindly multiplies combinations of largest and smallest numbers assuming all 4-number products matter.

codeforcescompetitive-programmingflowsgraph-matchingsgraphs
Kvant Math Problem 1555

Consider two disjoint circles $\Gamma_1$ and $\Gamma_2$ with centers $O_1$ and $O_2$ and radii $r_1$ and $r_2$.

kvantmathematicsolympiad
CF 1404C - Fixed Point Removal

Codeforces 1404C is a difficult 2300-rated offline-query problem. Producing a correct editorial and solution requires reconstructing the full proof and implementation details of the accepted approach.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1404A - Balanced Bitstring

We are given a string of length $n$ consisting of characters 0, 1, and ?, and an integer $k$ that is even. Our goal is to replace the ? characters with 0 or 1 so that every substring of length $k$ contains exactly $k/2$ zeroes and $k/2$ ones.

codeforcescompetitive-programmingimplementationstrings
CF 1405B - Array Cancellation

Let’s analyze the first test: The correct result is: So we are clearly choosing 4 elements, not 3. Now check the last test: 945 factors as: Those correspond to: So again: we are selecting 4 numbers, not 3 Your previous logic is effectively solving: “maximum product of 3…

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1405A - Permutation Forgery

We are asked to manipulate permutations of integers from 1 to n. Each permutation has a “fingerprint,” which is the sorted list of sums of every pair of consecutive elements.

codeforcescompetitive-programmingconstructive-algorithms
CF 1406C - Link Cut Centroids

The issue is not actually with the algorithm. The output shown as: means the program produced no output at all. That indicates an implementation problem, not a mathematical one.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstrees
CF 1406B - Maximum Product

I’ve traced the issue carefully. The root cause of your wrong output is not just input reading. The underlying problem is that your algorithm is misinterpreting the input sequence.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationsortings
CF 1406E - Deleting Numbers

We are asked to identify a hidden integer x between 1 and n. Initially, we have the full set of integers from 1 to n.

codeforcescompetitive-programminginteractivemathnumber-theory
CF 1406D - Three Sequences

We are given a sequence of integers a of length n. The task is to split it into two sequences b and c of the same length such that each element in a is the sum of the corresponding elements in b and c.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedymath
CF 1406A - Subset Mex

We are given a multiset of integers and we are allowed to redistribute its elements into two groups, call them A and B, without changing how many copies of each value exist overall. Every element must go to exactly one of the two groups, but duplicates can be split arbitrarily.

codeforcescompetitive-programminggreedyimplementationmath
CF 1407C - Chocolate Bunny

Now it’s clear why your solution fails. The traceback: This comes from trying to access a[j] for j in range(6) (the original guitar solution assumes 6 strings) while your input is not the 1413C guitar problem.

codeforcescompetitive-programmingconstructive-algorithmsinteractivemathtwo-pointers
CF 1407E - Egor in the Republic of Dagestan

We are asked to control Egor's travel through a directed graph of cities connected by roads of two types: night roads and morning roads. Each city can be assigned a color, black (night) or white (morning). Egor can leave a city only along roads that match its color.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgraphsgreedyshortest-paths
CF 1407D - Discrete Centrifugal Jumps

We are given a sequence of skyscrapers in a line, each with a fixed height. A person starts on the first skyscraper and wants to reach the last one using as few jumps as possible. The twist is that not every forward jump is allowed.

codeforcescompetitive-programmingdata-structuresdpgraphs
CF 1407B - Big Vova

We are given a sequence of positive integers, and we need to reorder them into a sequence $b$ such that the sequence of prefix greatest common divisors $ci = gcd(b1, b2, dots, bi)$ is lexicographically maximal.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1407A - Ahahahahahahahaha

We are given several independent test cases. Each test case contains a binary array of even length. We are allowed to delete elements anywhere in the array, but we can delete at most half of them.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1408I - Bitwise Magic

We are given an array of distinct non-negative integers, each at least as large as a given integer $k$, and we perform $k$ random decrements on the array. Each second, one of the $n$ elements is chosen uniformly at random and decreased by 1.

codeforcescompetitive-programmingdpmath
CF 1408A - Circle Coloring

Your traceback repeatedly shows: This tells us two important facts: 1. You are still running a wrapper-based tester (run) that expects a solve() function 2. The code being tested is not consistently redefining solve() in the same execution scope 3.

codeforcescompetitive-programmingconstructive-algorithms
CF 1408G - Clusterization Counting

We are given a complete graph on n computers. Every edge has a unique weight a[i][j], representing the difficulty of communication between those two computers. We want to partition the vertices into groups.

codeforcescompetitive-programmingcombinatoricsdpdsufftgraphstrees
CF 1408H - Rainbow Triples

We are given an array of integers where the value zero plays a special role. We want to extract as many disjoint triples of indices as possible, and each triple must have a very rigid structure: it must look like a zero, then a non-zero value, then another zero.

codeforcescompetitive-programmingbinary-searchdata-structuresflowsgreedy
CF 1408F - Two Different

We are asked to construct a sequence of operations on an array of size $n$ that starts as $[1, 2, dots, n]$. Each operation chooses two positions $x$ and $y$ and replaces both $ax$ and $ay$ with a value returned by an arbitrary function $f(ax, ay)$.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquer
CF 1408E - Avoid Rainbow Cycles

We are given a collection of sets of integers, where each set represents a group of vertices in a graph. Each set has an associated cost ai for deleting any element from it, and each element has a deletion cost bj. The deletion cost for removing element j from set i is ai + bj.

codeforcescompetitive-programmingdata-structuresdsugraphsgreedysortingstrees
CF 1408D - Searchlights

We are given a set of robbers positioned on a 2D grid and a set of searchlights, each with a fixed location. Robbers move in a constrained way: in a single move, all robbers either increase their x-coordinate by one or increase their y-coordinate by one.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpimplementationsortingstwo-pointers
CF 1408C - Discrete Acceleration

Two cars start at opposite ends of a road of length l. The left car starts at position 0 and moves to the right. The right car starts at position l and moves to the left. Both cars begin with speed 1. Along the road there are flags placed at fixed coordinates.

codeforcescompetitive-programmingbinary-searchdpimplementationmathtwo-pointers
CF 1408B - Arrays Sum

We are given a non-decreasing array a where each entry is a non-negative integer. We want to split this array into a sum of m arrays b₁, b₂, ..., bₘ such that each bᵢ is also non-decreasing and has a strong structural restriction: it uses at most k distinct values.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1409C - Yet Another Array Restoration

The root cause of the failure here is the test harness is trying to call a solve() function that isn’t defined in the same context.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1409F - Subsequences of Length Two

We are given a base string and a target string of length two. We are allowed to change at most k characters in the base string, replacing any position with any lowercase letter.

codeforcescompetitive-programmingdpstrings
CF 1409E - Two Platforms

We are given a set of points on a 2D plane, each with coordinates $(xi, yi)$, and two horizontal platforms of fixed length $k$. The platforms can be positioned anywhere along the $x$-axis at any $y$-coordinate, but they must remain horizontal.

codeforcescompetitive-programmingbinary-searchdpsortingstwo-pointers
CF 1409D - Decrease the Sum of Digits

We are given a large integer and a threshold on the sum of its digits. In a single operation we are allowed to increment the number by one, and we want to know how many increments are needed until the digit sum of the resulting number becomes small enough, specifically at most…

codeforcescompetitive-programminggreedymath
CF 1409B - Minimum Product

We start with two numbers, a and b. We are allowed to perform at most n decrement operations. Each operation decreases either a or b by exactly one. The catch is that a can never go below x, and b can never go below y.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1409A - Yet Another Two Integers Problem

We are given two integers, and we want to transform the first into the second using a sequence of moves. Each move allows us to pick any integer step size from 1 to 10 and either add it to or subtract it from the current value.

codeforcescompetitive-programminggreedymath