brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1773B - BinCoin

We are given a rooted binary tree with $n$ employees. Each employee has either zero or two direct subordinates, and there is a unique root (the CEO).

codeforcescompetitive-programmingbinary-searchdivide-and-conquerhashingimplementationprobabilitiestrees
CF 1773A - Amazing Trick

We are given a permutation $a$ of size $n$, meaning every number from $1$ to $n$ appears exactly once. We are allowed to apply two permutations $q$ first and then $p$, so that the final position $i$ receives the value originally at position $p[q[i]]$.

codeforcescompetitive-programmingconstructive-algorithmsgraph-matchingsmathprobabilities
CF 1773E - Easy Assembly

We are given several vertical stacks of uniquely numbered blocks. Each stack is ordered from top to bottom, and we are allowed to physically reorganize these blocks using two operations: we can cut a stack into two by taking a prefix or suffix segment and turning it into a new…

codeforcescompetitive-programminggreedysortings
CF 1740I - Arranging Crystal Balls

We are given a circular arrangement of $n$ positions, each holding a value modulo $m$. The goal is to transform every value into zero.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgeometrygraphsnumber-theory
CF 1740G - Dangerous Laser Power

We are given an (n times m) grid where each cell behaves like a directional device that routes a “laser” entering from one side to another side, while possibly increasing its speed.

codeforcescompetitive-programmingconstructive-algorithmsdsusortings
CF 1740H - MEX Tree Manipulation

I can’t produce a correct editorial for “Codeforces 1740H - MEX Tree Manipulation” from the title alone. That problem number corresponds to a very specific and fairly technical tree + data structure task, and without the exact statement (operations, constraints, and what…

codeforcescompetitive-programmingdata-structurestrees
CF 1740F - Conditional Mix

We start with a collection of $n$ single-element sets, one for each value in the array. Each position contributes a separate set, even if values repeat. The only operation allowed is merging two currently existing sets, but only if they are disjoint as sets of values.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1740E - Hanging Hearts

We are given a rooted tree where each node represents a card. Card 1 is fixed as the root, and every other card hangs from exactly one earlier card, forming a structure where every node has a single parent and edges always point toward smaller indices.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardpgreedytrees
CF 1740D - Knowledge Cards

We are given a grid, but only two cells actually behave like “real endpoints”: the top-left cell acts as a source holding a stack of cards, and the bottom-right cell acts as a sink where we must rebuild a stack in sorted order from 1 to k, increasing from top to bottom.

codeforcescompetitive-programmingconstructive-algorithmsdata-structures
CF 1740A - Factorise N+M

We are given several test cases, and each test case starts with a prime number $n$. For every such $n$, we must choose another prime number $m$ such that the sum $n + m$ is not prime.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
CF 1740C - Bricks and Bags

We are given a multiset of integer weights representing bricks, and we must distribute every brick into one of three non-empty groups.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedysortings
CF 1740B - Jumbo Extra Cheese 2

We are given several test cases. In each test case, we receive a collection of rectangles, each representing a cheese slice. Each slice can be rotated, so a rectangle $a times b$ can be treated as either width $a$, height $b$ or width $b$, height $a$.

codeforcescompetitive-programminggeometrygreedysortings
CF 1734F - Zeros and Ones

The construction defines an infinite binary string where each stage doubles the previous string and flips the bits in the second half.

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpmath
CF 1734E - Rectangular Congruence

We are asked to construct an $n times n$ matrix over the field of residues modulo a prime $n$. Every entry must be an integer in the range $0$ to $n-1$, and the diagonal is already fixed: the $i$-th diagonal entry must equal $bi$.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
CF 1734D - Slime Escape

We start at position k on a line of n slimes. Each position contains a slime with some health value, and when we step onto a position that still has a slime, we absorb it and add its health to ours. Negative values reduce our health, positive values increase it.

codeforcescompetitive-programmingdata-structuresdpgreedytwo-pointers
CF 1734B - Bright, Nice, Brilliant

The structure is a triangular grid where row i contains i cells, and each cell can send influence downward to two children: directly below-left and below-right.

codeforcescompetitive-programmingconstructive-algorithms
CF 1733E - Conveyor

The system describes a 120 by 120 grid where every cell initially contains a conveyor belt pointing to the right. A single slime starts at the top-left cell, and every second the system evolves in a synchronized way.

codeforcescompetitive-programmingconstructive-algorithmsdpmath
CF 1733D1 - Zero-One (Easy Version)

We are given two binary strings of equal length. We are allowed to repeatedly apply an operation that flips two positions at once: pick indices l and r with l < r, and invert both bits. The cost depends only on whether the chosen positions are adjacent or not.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1733D2 - Zero-One (Hard Version)

We are given two binary strings of equal length. We are allowed to fix mismatches between them by flipping pairs of positions in the first string. Each operation picks two different indices and toggles both bits at those positions.

codeforcescompetitive-programmingdpgreedy
CF 1733A - Consecutive Sum

We are given an array of integers, and we are allowed to rearrange elements using a restricted swap operation. The restriction is that we can only swap positions whose indices share the same remainder when divided by a fixed number $k$.

codeforcescompetitive-programminggreedysortings
CF 1733C - Parity Shuffle Sorting

We are given an array of integers and a peculiar operation that allows us to “transfer” values between two positions, but the direction of the transfer depends entirely on the parity relationship between the chosen pair. Each operation picks two indices l < r.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1733B - Rule of League

We are given a very specific elimination-style tournament. Players arrive in a fixed order from 1 to n. The first match is between player 1 and player 2, then the winner of that match plays player 3, then that winner plays player 4, and so on until player n.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1732E - Location

Each position in the array behaves like a pair of values, a dynamic value $ai$ and a fixed value $bi$. Over time, we repeatedly overwrite entire segments of the $a$-array with a single number, and occasionally we are asked to inspect a segment and find the smallest value of a…

codeforcescompetitive-programmingdata-structuresdpmathnumber-theory
CF 1732D2 - Balance (Hard version)

We maintain a dynamic set of non-negative integers. It starts with a single element, zero, and evolves through three types of operations: insert a new number, delete an existing number, and answer a query that depends on a parameter $k$.

codeforcescompetitive-programmingbrute-forcedata-structuresnumber-theory
CF 1732D1 - Balance (Easy version)

We start with a set that initially contains only the number zero. Over time, two kinds of operations are applied. One operation inserts a new integer into the set, and the other asks a query about a special value called the k-mex.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationnumber-theory
CF 1732B - Ugu

We are given a binary string, and we want to transform it into a non-decreasing sequence, meaning that once the string starts containing 1, it should never go back to 0. The final form must look like some number of 0s followed by some number of 1s.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementation
CF 1732C2 - Sheikh (Hard Version)

We are given an array and multiple range queries. For each query interval, we must choose a contiguous subarray fully inside that interval and maximize a score defined on that subarray.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcegreedyimplementationtwo-pointers
CF 1732C1 - Sheikh (Easy version)

We are given an array and we are allowed to choose any contiguous segment inside it. For each segment, we compute a score defined as the difference between its sum and its bitwise XOR.

codeforcescompetitive-programmingbinary-searchbitmasksgreedytwo-pointers
CF 1731B - Kill Demodogs

We are working on an $n times n$ grid where each cell $(i, j)$ contains a value equal to the product $i cdot j$. A character starts at the top-left corner $(1, 1)$ and must reach the bottom-right corner $(n, n)$, moving only right or down at each step.

codeforcescompetitive-programminggreedymath
CF 1731E - Graph Cost

We start with a graph of $n$ labeled vertices and no edges. The goal is to end with exactly $m$ undirected edges. Each edge between vertices $u$ and $v$ is not freely chosen: its weight is fixed and equals $gcd(u, v)$.

codeforcescompetitive-programmingdpgreedymathnumber-theory
CF 1731D - Valiant's New Map

We are given several independent grids, each grid representing a city map where every cell contains a building height. From each grid, we must choose a square subgrid of size $l times l$ such that every cell inside that square has height at least $l$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdptwo-pointers
CF 1731C - Even Subarrays

We are given an array of integers, and we look at every contiguous segment of it. For each segment we compute the bitwise XOR of its elements, producing a single number.

codeforcescompetitive-programmingbitmasksbrute-forcehashingmathnumber-theory
CF 1730F - Almost Sorted

We are given a permutation p of size n, and we must construct another permutation q of indices 1..n. The constraint on q is unusual: if we look at the values of p along q, they cannot drop by more than k as we move forward.

codeforcescompetitive-programmingbitmasksdata-structuresdp
CF 1730E - Maximums and Minimums

The task is to count how many contiguous subarrays of a given array have a very specific structural property: if you look inside the subarray, take its smallest element and its largest element, the larger one must be an exact multiple of the smaller one.

codeforcescompetitive-programmingcombinatoricsdata-structuresdivide-and-conquernumber-theory
CF 1730D - Prefixes and Suffixes

We are given two strings of equal length. Think of them as two rows of characters, each row having $n$ positions.

codeforcescompetitive-programmingconstructive-algorithmsstringstwo-pointers
CF 1730B - Meeting on the Line

We are given a line with people standing at different coordinates. Each person has a fixed position and also a personal preparation time before they can start moving.

codeforcescompetitive-programmingbinary-searchgeometrygreedyimplementationmathternary-search
CF 1730A - Planets

We are given several independent test cases. In each test case there is a multiset of integers, where each integer represents an orbit label of a planet. Planets sharing the same value belong to the same orbit. We have two ways to destroy planets.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1729E - Guess the Cycle Size

We are interacting with a hidden structure that is guaranteed to be a simple cycle on $n$ vertices, where $n$ can be as large as $10^{18}$. The vertices are labeled by distinct integers, but the actual cycle order is unknown.

codeforcescompetitive-programminginteractiveprobabilities
CF 1729G - Cut Substrings

We are given a text string and a pattern string. The operation allowed is to pick any occurrence of the pattern inside the text and replace that entire occurrence with dots. Those dots still occupy positions but no longer participate in further pattern matches.

codeforcescompetitive-programmingcombinatoricsdphashingstringstwo-pointers
CF 1729D - Friends and the Restaurant

We are given a collection of friends where each friend has two numbers: how much they intend to spend at a restaurant and how much money they actually have. The goal is to partition some of these friends into disjoint groups, where each group has at least two people.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 1729C - Jumping on Tiles

We are given a string of lowercase letters representing a line of tiles. Each position is a node in a path from the first character to the last, but we are not required to move only to adjacent positions.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1729B - Decode String

We are given a string that was produced by encoding a lowercase English string character by character. Each letter was replaced by its position in the alphabet, with the extra twist that two-digit positions are marked by appending an extra 0 after the number.

codeforcescompetitive-programminggreedystrings
CF 1729A - Two Elevators

The situation describes a decision between two elevators that can potentially reach Vlad on the 1st floor. Each elevator has a different movement rule, and the goal is to determine which one arrives back to floor 1 the fastest after Vlad presses a call button.

codeforcescompetitive-programmingmath
CF 1728G - Illumination

We are working on a one-dimensional segment from 0 to d. Some positions on this line are special points that must be “covered”. We also have a collection of lantern positions, and each lantern can be assigned a nonnegative power up to d.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcecombinatoricsdpmathtwo-pointers
CF 1728E - Red-Black Pepper

Each dish must receive exactly one seasoning choice: either red pepper or black pepper. If a dish uses red pepper, it contributes $ai$ to the total tastiness, otherwise it contributes $bi$. So the final score is fully determined once we decide a binary assignment for all dishes.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathnumber-theory
CF 1728A - Colored Balls: Revisited

We are given several test cases. In each test case, there are several colors of balls, and each color has a certain number of balls. The total number of balls across all colors is guaranteed to be odd.

codeforcescompetitive-programmingbrute-forcegreedyimplementationsortings
CF 1728C - Digital Logarithm

We are given two arrays of equal length. Each position contains a positive integer, and we are allowed to repeatedly replace a number by the number of digits it has in base 10.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1728D - Letter Picking

We are playing a two-player game on a string that behaves like a deque. The string initially contains lowercase letters and has even length. Alice moves first, and players alternate.

codeforcescompetitive-programmingconstructive-algorithmsdpgamestwo-pointers
CF 1726H - Mainak and the Bleeding Polygon

We are given a convex polygon described by its vertices in counter-clockwise order. The shape is not arbitrary: every corner is either a right angle or slightly wider than a right angle, but never sharp.

codeforcescompetitive-programmingbinary-searchgeometryimplementationmath
CF 1726G - A Certain Magical Party

We are given a group of $n$ people, each starting with a happiness value $ai$ and a binary personality flag $bi$. We choose a permutation, which represents the order in which they speak.

codeforcescompetitive-programmingcombinatoricsdata-structuresgreedysortings
CF 1726E - Almost Perfect

We are asked to count how many permutations of size $n$ satisfy a very specific structural constraint involving both the permutation and its inverse.

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1726D - Edge Split

We are given a connected undirected graph with a small number of extra edges beyond a tree. For each edge, we must decide whether it is colored red or blue.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardsugraphsprobabilitiestrees
CF 1726C - Jatayu's Balanced Bracket Sequence

We are given a balanced bracket string of length $2n$. Each position in this string is treated as a vertex in a graph. Two vertices $i$ and $j$ are connected by an undirected edge exactly when the substring from $i$ to $j$ forms a balanced bracket sequence on its own.

codeforcescompetitive-programmingdata-structuresdsugraphsgreedy
CF 1726B - Mainak and Interesting Sequence

We are asked to construct a sequence of positive integers of length $n$ whose sum is fixed to $m$, but with an additional constraint that comes from a peculiar XOR condition applied to value ordering rather than positions.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 1726A - Mainak and Array

We are given an array of positive integers. Exactly once, we are allowed to choose a contiguous segment and rotate it cyclically by any amount, which effectively means we can pick any element inside the segment and move it to either end of that segment, while preserving the…

codeforcescompetitive-programminggreedymath
CF 1725L - Lemper Cooking Competition

We are given a line of stoves, each carrying an integer temperature that may start negative or positive. The goal is to perform a sequence of local operations so that every stove ends up with a non-negative value.

codeforcescompetitive-programmingdata-structures
CF 1725M - Moving Both Hands

We are given a directed weighted graph where every edge allows movement in only one direction and has a cost in time. Two tokens, or “hands”, start on different vertices: one is fixed at vertex 1, and the other starts at some vertex p.

codeforcescompetitive-programmingdpgraphsshortest-paths
CF 1725H - Hot Black Hot White

We are given an array of integers, each representing the strength of a magical stone. We must split these stones into two equal groups and assign each stone one of two colors.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1725D - Deducing Sortability

We are asked to construct a very large hidden array indexed from 1 to N, where N can be up to one billion, without explicitly building it.

codeforcescompetitive-programmingbinary-searchbitmasksmath
CF 1725A - Accumulation of Dominoes

The grid in this problem is not arbitrary, it is completely determined by its dimensions. Every cell contains a unique integer, and the numbers increase row by row from left to right.

codeforcescompetitive-programmingmath
CF 1722G - Even-Odd XOR

We are asked to construct, for each test case, a sequence of distinct nonnegative integers, all strictly below $2^{31}$, with a very specific balancing condition.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 1722E - Counting Rectangles

We are given a collection of axis-aligned rectangles, each defined by its height and width. For every query, we are also given two bounding rectangles: a “small inner constraint” rectangle and a “large outer constraint” rectangle.

codeforcescompetitive-programmingbrute-forcedata-structuresdpimplementation
CF 1722D - Line

We are given a row of people, each either facing left or right. The contribution of a person depends on how many people lie in the direction they are looking.

codeforcescompetitive-programminggreedysortings
CF 1722C - Word Game

Each test case describes a small three-player word submission game. Every player independently writes down the same number of short strings, each string having length exactly three. After all words are written, scoring is determined by how many people included each distinct word.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1722B - Colourblindness

We are given a very small grid with exactly two horizontal strips and some number of vertical columns. Each cell contains one of three colors, but the viewer is colorblind in a specific way: green and blue are indistinguishable, while red remains distinct from both.

codeforcescompetitive-programmingimplementation
CF 1722A - Spell Check

We are given a short string in each test case and we need to decide whether it can be interpreted as a rearrangement of the name “Timur” under a very specific spelling rule. The rule is not just that the letters match.

codeforcescompetitive-programmingimplementation
CF 1721F - Matching Reduction

We are working with a bipartite graph where the left side has $n1$ vertices and the right side has $n2$ vertices. Edges are fixed and each edge connects one left vertex to one right vertex.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similarflowsgraph-matchingsgraphsinteractive
CF 1721E - Prefix Function Queries

We are given a fixed reference string and then asked to process many short query strings. For each query, we temporarily append the query string to the reference, compute the prefix function on the resulting concatenation, and output only the prefix function values…

codeforcescompetitive-programmingdfs-and-similardphashingstring-suffix-structuresstringstrees
CF 1721D - Maximum AND

We are given two arrays of equal length. One array, call it a, is fixed in place. The second array b can be permuted arbitrarily. After choosing a permutation of b, we pair elements by index and form a new array where each position becomes the XOR of the paired values.

codeforcescompetitive-programmingbitmasksdfs-and-similardivide-and-conquergreedysortings
CF 1721B - Deadly Laser

We are working on a grid where a robot starts at the top-left corner and wants to reach the bottom-right corner using four-directional moves.

codeforcescompetitive-programmingimplementation
CF 1721A - Image

We are given a tiny image made of four pixels arranged in a 2 by 2 grid. Each pixel is labeled with a lowercase letter, representing its current color. The goal is to make all four pixels end up with the same color using a sequence of painting operations.

codeforcescompetitive-programminggreedyimplementation
CF 1721C - Min-Max Array Transformation

We are given two non-decreasing arrays, one original array and one final array. The original array can be “shifted” element by element by adding a non-negative value to each position, producing an intermediate array.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1720E - Misha and Paintings

We are given an $n times n$ grid of integers. Each cell initially contains some value, and we are allowed to perform an operation that selects any square submatrix and overwrites every cell inside it with a single chosen integer.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationmath
CF 1720D2 - Xor-Subsequence (hard version)

We are given an array of integers, and we want to choose a subsequence of indices. The chosen indices must be strictly increasing in position, but the values we compare are not just the array values themselves.

codeforcescompetitive-programmingbitmasksdata-structuresdpstringstrees
CF 1720D1 - Xor-Subsequence (easy version)

We are given an array of integers where each value is small, but the index range can be large. From this array we want to pick a subsequence of positions, keeping the indices strictly increasing.

codeforcescompetitive-programmingbitmasksbrute-forcedpstringstreestwo-pointers
CF 1720C - Corners

We are given a binary grid where each cell is either empty or contains a single unit. The only allowed move is to pick a 2 by 2 block and choose three of its four cells forming an L shape.

codeforcescompetitive-programminggreedyimplementation
CF 1720B - Interesting Sum

We are given an array of integers, and we are allowed to pick a single contiguous segment inside it, but not the whole array. Once we choose this segment, the array is conceptually split into two parts: the chosen segment and everything outside it.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathsortings
CF 1720A - Burenka Plays with Fractions

Each test case gives two fractions, $frac{a}{b}$ and $frac{c}{d}$. In one move, you are allowed to pick exactly one of the four numbers $a, b, c, d$ and multiply it by any nonzero integer.

codeforcescompetitive-programmingmathnumber-theory
CF 1719B - Mathematical Circus

We are given an even number $n$, and we must partition the integers from $1$ to $n$ into disjoint pairs. Each number must appear in exactly one pair, and the order inside each pair matters. For a pair $(a, b)$, we compute the expression $(a + k) cdot b$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1719C - Fighting Tournament

The tournament can be viewed as a queue that evolves over time. At the beginning, all athletes are arranged in increasing order of their indices.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationtwo-pointers
CF 1718D - Permutation for Burenka

We are given a permutation p of size n, which acts as a reference order. Alongside it, we have an array a of the same size where some positions are already filled with numbers and exactly k positions are missing (marked as zero).

codeforcescompetitive-programmingdata-structuresgraph-matchingsgreedymathtrees
CF 1718E - Impressionism

We are given two rectangular grids of the same size, and each grid contains colored cells. The only allowed operations are swapping entire rows or swapping entire columns.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementationmath
CF 1718F - Burenka, an Array and Queries

We are given an array where each element is a small positive integer, and we are asked to answer many independent range queries. Each query selects a contiguous subarray and conceptually multiplies all values inside it into a single large number.

codeforcescompetitive-programmingdata-structuresmathnumber-theory
CF 1718C - Tonya and Burenka-179

We are given a circular array, and we repeatedly simulate a very specific traversal rule. We choose a starting position s and a fixed jump length k. Starting from s, we walk exactly n steps.

codeforcescompetitive-programmingdata-structuresgreedymathnumber-theory
CF 1718A2 - Burenka and Traditions (hard version)

We are given an array of integers, and the goal is to transform every element into zero using a special range operation. Each operation lets us choose a contiguous segment and XOR every element in that segment with the same value.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1718A1 - Burenka and Traditions (easy version)

We are given several independent test cases. In each one, an array of integers is provided, and the goal is to turn every element into zero using a special operation.

codeforcescompetitive-programmingdpgreedy
CF 1712E2 - LCM Sum (hard version)

We are given many queries, and each query describes a contiguous interval of integers from l to r. For each such interval, we want to count how many triples (i, j, k) can be formed with strictly increasing indices inside the interval such that the least common multiple of the…

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theorytwo-pointers
CF 1712E1 - LCM Sum (easy version)

We are given many independent queries, each query defines a numeric segment from $l$ to $r$. Inside that segment we consider all triples of distinct indices $i < j < k$, and we want to count how many of these triples satisfy a specific inequality: the least common multiple of…

codeforcescompetitive-programmingbinary-searchbrute-forcecombinatoricsmathnumber-theorytwo-pointers
CF 1712F - Triameter

We are given a tree with unit-weight edges. From this tree we identify a special set of vertices, the leaves, meaning the vertices whose degree is exactly one.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similartrees
CF 1712D - Empty Graph

We are given an array where each position represents a node in a line. Between any two indices $l$ and $r$, there is an edge whose weight is the minimum value in the subarray $al, dots, ar$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedyshortest-paths
CF 1712C - Sort Zero

We are given several independent test cases, each consisting of an array of positive integers. In one move, we are allowed to pick a value x and simultaneously erase all occurrences of x in the array by turning them into zeros.

codeforcescompetitive-programminggreedysortings
CF 1712B - Woeful Permutation

We are given a single integer $n$, and we must arrange the numbers from $1$ to $n$ into a permutation so that a particular score is as large as possible.

codeforcescompetitive-programmingconstructive-algorithmsgreedynumber-theory
CF 1658D1 - 388535 (Easy Version)

We are given a final array that was produced by taking a consecutive integer segment, permuting it, and then applying a fixed XOR mask to every element. The original segment is known to be all integers from l to r inclusive, but their order is scrambled.

codeforcescompetitive-programmingbitmasksmath
CF 1658E - Gojou and Matrix Game

The game is played on an $n times n$ grid where each cell has a fixed value, and all values are distinct so there are no ties in scoring from identical weights.

codeforcescompetitive-programmingdata-structuresdpgameshashingimplementationmathnumber-theorysortings
CF 1658D2 - 388535 (Hard Version)

We are given a hidden construction process that starts with a clean consecutive integer segment from some interval $[l, r]$. Gojou first takes all integers in that interval, then shuffles them arbitrarily.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresmath
CF 1656I - Neighbour Ordering

We are given a connected undirected graph, and we are allowed to choose, independently for every vertex, an ordering of its adjacent vertices.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 1656G - Cycle Palindrome

We are given an array of integers and we are allowed to reorder its indices using a very restricted type of permutation: a single cycle that visits every position exactly once before returning to the start.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmath
CF 1656H - Equal LCM Subsets

We are given two finite collections of very large positive integers, think of them as two bags of numbers. From each bag we are allowed to pick any non-empty subcollection. For each chosen subcollection, we compute the least common multiple of all its elements.

codeforcescompetitive-programmingdata-structuresmathnumber-theory
CF 1656F - Parametric MST

We are given an array of integers, and we build a complete graph where every pair of vertices is connected. The weight of an edge between vertices $i$ and $j$ depends on a parameter $t$ and is defined as a linear function in $t$: it has a fixed quadratic-looking term $ai aj$…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgraphsgreedymathsortings
CF 1656D - K-good

We are given a number $n$, and we want to check whether there exists an integer $k ge 2$ such that we can split $n$ into exactly $k$ positive integers with a special property: when each of those $k$ numbers is divided by $k$, all remainders must be different.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory