brain

tamnd's digital brain — notes, problems, research

41650 notes

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 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 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 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
CF 1656E - Equal Tree Sums

We are given a tree, and we must assign a nonzero integer to every vertex. The constraint is not about the whole tree sum, but about what happens when a vertex is removed. If we delete any vertex $v$, the tree splits into several connected components.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarmathtrees
CF 1654D - Potion Brewing Class

We are given a set of ingredients, each of which must appear in some positive integer quantity in a final mixture. The professor does not provide absolute amounts, but instead gives exactly $n-1$ constraints.

codeforcescompetitive-programmingdfs-and-similarmathnumber-theorytrees
CF 1654H - Three Minimums

We are asked to count permutations of the numbers from 1 to n that satisfy two independent kinds of restrictions. The first restriction is positional and local. We are given a short comparison string s of length m.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdivide-and-conquerdpfftmath
CF 1654G - Snowy Mountain

We are given a tree where some vertices are marked as “base lodges”. Every vertex inherits a height equal to its distance from the nearest lodge.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsgreedyshortest-pathstrees
CF 1654B - Prefix Removals

We are repeatedly trimming a string from the front based on a self-referential property of its prefixes. At any moment, we look at the current string and examine all its prefixes starting from the empty one.

codeforcescompetitive-programmingstrings
CF 1654F - Minimal String Xoration

We are given a string whose length is a power of two, indexed from 0 to $2^n - 1$. The key operation allowed is a global reindexing of the string using bitwise XOR with a fixed mask $j$.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquergreedyhashingsortingsstrings
CF 1646F - Playing Around the Table

We are given a circular arrangement of $n$ players, each holding exactly $n$ cards. Every card carries a label from $1$ to $n$, and each label appears exactly $n$ times across the whole system.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1646E - Power Board

We are looking at a grid where each position is completely deterministic: the cell in row $i$ and column $j$ contains the value $i^j$.

codeforcescompetitive-programmingbrute-forcedpmathnumber-theory
CF 1646D - Weight the Tree

We are given a tree, and we must assign a positive integer weight to every vertex. A vertex is called good if its weight equals the sum of the weights of all vertices adjacent to it. The goal is not just to satisfy this condition arbitrarily.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpimplementationtrees
CF 1593B - Make it Divisible by 25

We are given a number written in decimal form, and we are allowed to delete digits one by one from anywhere in the number. After each deletion, the remaining digits close up, and any leading zeros disappear automatically.

codeforcescompetitive-programmingdfs-and-similardpgreedymath
CF 1593G - Changing Brackets

We are given a string made of four types of brackets: round (, ) and square [ , ]. Each query gives a substring, and for that substring we want to know the cheapest way to turn it into a valid bracket sequence. We are allowed to perform two kinds of transformations.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgreedy
CF 1593C - Save More Mice

We are given a line segment with three types of entities: a cat starting at position 0, a hole at position n, and several mice positioned strictly between them. Time advances in discrete seconds.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1583H - Omkar and Tours

We are given a tree of cities. Each city has a fixed value called enjoyment. Each road connects two cities and has two properties: a capacity and a toll. A group query gives a starting city and a number of vehicles.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortingstrees
CF 1583E - Moment of Bloom

We are given a connected undirected graph where every edge initially has weight 0. We then receive a sequence of queries, each query specifying two vertices. For each query, we must choose a simple path between its endpoints and add 1 to every edge along that path.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraph-matchingsgraphsgreedytrees
CF 1583G - Omkar and Time Travel

Each task has two special moments: the moment Okabe learns about it, and the earlier time at which it should actually be completed. When he learns about a task, he either confirms it is already done correctly, or he is forced to jump back in time to fix it immediately.

codeforcescompetitive-programmingdata-structuresmath
CF 1583F - Defender of Childhood Dreams

We are given a complete directed acyclic graph on the vertices from 1 to n, where every pair (i, j) with i < j has a directed edge from i to j.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquer
CF 1583B - Omkar and Heavenly Tree

We are asked to construct a tree on $n$ labeled nodes, where a tree means a connected graph with exactly $n-1$ edges and a unique simple path between every pair of nodes. Alongside this, we are given $m$ constraints.

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 1583D - Omkar and the Meaning of Life

We are trying to recover an unknown permutation of the numbers from 1 to n. We never see this permutation directly. Instead, we can probe it using a query mechanism that mixes our chosen array with the hidden permutation in a very specific way.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractive
CF 1583A - Windblume Ode

We are given several independent test cases. In each test case there is an array of distinct positive integers, and the task is to choose as many elements as possible such that the sum of the chosen elements is not prime.

codeforcescompetitive-programmingmathnumber-theory
CF 1582G - Kuzya and Homework

We are given a sequence of numbers and a sequence of operations placed between them. We start each segment with value 1, then apply the operations from left to right. Each position either multiplies the current value by the given number or divides it by that number.

codeforcescompetitive-programmingdata-structuresnumber-theory
CF 1582E - Pchelyonok and Segments

We are given an array of positive integers and asked to construct a sequence of non-overlapping subarrays. These subarrays must be chosen in order from left to right, and their lengths are fixed to form a decreasing sequence starting from some value $k$ down to $1$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedymath
CF 1582D - Vupsen, Pupsen and 0

We are given several test cases. In each one, we start with an array of nonzero integers $a$. Our task is to construct another array $b$ of the same length such that two conditions hold simultaneously. First, no element of $b$ is allowed to be zero.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1582C - Grandma Capa Knits a Scarf

We are given a string made of lowercase letters. We are allowed to pick exactly one letter of the alphabet, and then delete any occurrences of that chosen letter from the string, possibly none or all of them.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedystringstwo-pointers
CF 1582A - Luntik and Concerts

We are given a collection of songs split into three types: some last 1 minute, some last 2 minutes, and some last 3 minutes. For each test case, we must assign every song to one of two concerts.

codeforcescompetitive-programmingmath
CF 1578M - The Mind

Each test gives us a hand of five distinct numbers between 1 and 100. Two players independently receive such hands, and each player only sees their own five numbers.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilities
CF 1578L - Labyrinth

The labyrinth can be seen as a connected weighted graph where rooms are nodes and passages are undirected edges with capacities. Each room also has a one-time “growth value” that increases Lucy’s width if she chooses to eat that room’s candy.

codeforcescompetitive-programmingbinary-searchdsugreedy
CF 1578K - Kingdom of Islands

We are given a set of jarls, each belonging to exactly one island. The default rule of conflict is simple: jarls from different islands are in conflict, while jarls from the same island are peaceful.

codeforcescompetitive-programmingbrute-forcegraphsimplementation
CF 1578J - Just Kingdom

We are given a rooted hierarchy with a single root, the king, and up to $n$ lords forming a tree where each lord has exactly one parent. Each lord $i$ has a required amount of money $mi$.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similar
CF 1578F - Framing Pictures

We are given a convex polygon in the plane, and this polygon represents the silhouette of an object. We imagine rotating the viewing direction uniformly at random, and for each orientation we project the polygon onto axes aligned with that view.

codeforcescompetitive-programminggeometry
CF 1578G - Game of Chance

We are given a line of participants, each assigned a positive “luckiness” value. These participants enter a knockout tournament with a very rigid pairing structure.

codeforcescompetitive-programmingmathprobabilities
CF 1578B - Building Forest Trails

We are given a circular arrangement of villages, labeled from 1 to n in clockwise order. Initially there are no connections between any pair of villages.

codeforcescompetitive-programmingdata-structuresdsu
CF 1578A - Anti-Tetris

We are given a final board configuration of a grid-based stacking process where multiple small polyomino-like pieces were dropped one after another. Each piece is connected in four directions, has at most seven cells, and is identified by a letter.

codeforcescompetitive-programmingconstructive-algorithmsgraphsshortest-paths
CF 1561A - Simply Strange Sort

We are given a permutation, meaning an array containing every integer from 1 to n exactly once. The process repeatedly applies a deterministic “strange bubble pass” operation, but with a twist: odd-numbered rounds compare adjacent pairs starting from index 1, 3, 5, and…

codeforcescompetitive-programmingbrute-forceimplementationsortings
CF 1560F1 - Nearest Beautiful Number (easy version)

We are given a starting number and a restriction on how many distinct digits we are allowed to use. For each query, we must find the smallest integer that is not smaller than the given number and whose decimal representation uses at most k different digits.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceconstructive-algorithmsdfs-and-similargreedy
CF 1560D - Make a Power of Two

We are given a number written as a string of digits. In one operation, we are allowed to either remove any single digit from anywhere in the current string, or append a single digit to the right end of the string. These operations can be repeated in any order.

codeforcescompetitive-programminggreedymathstrings
CF 1557C - Moamen and XOR

We are counting how many arrays of length n can be formed when each element is an integer in the range [0, 2^k - 1], with the additional constraint that a certain bitwise inequality holds.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathmatrices
CF 1556H - DIY Tree

We are given a complete weighted undirected graph on $n$ vertices, so every pair of vertices is connected and every edge has a known cost.

codeforcescompetitive-programminggraphsgreedymathprobabilities
CF 1556G - Gates to Another World

We are working on a graph whose vertices are all integers from $0$ to $2^n - 1$. Each vertex represents an $n$-bit binary string, and there is an undirected edge between two vertices if their binary representations differ in exactly one bit.

codeforcescompetitive-programmingbitmasksdata-structuresdsutwo-pointers
CF 1556D - Take a Guess

We are given a hidden array of integers, and we cannot access its elements directly. The only way to learn anything about the array is by asking queries on pairs of indices. Each query returns either the bitwise AND or bitwise OR of two elements.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1556E - Equilibrium

We are given two arrays of the same length and a set of queries, each query picking a contiguous segment. Inside a segment, we are allowed to perform a special operation multiple times. Each operation selects an even number of distinct positions inside the segment.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1556F - Sports Betting

We are given a complete tournament where every pair of teams plays exactly one match. The result of each match is random, but biased: team $i$ beats team $j$ with probability proportional to its strength, specifically $frac{ai}{ai + aj}$. Each match outcome is independent.

codeforcescompetitive-programmingbitmaskscombinatoricsdpgraphsmathprobabilities
CF 1556C - Compressed Bracket Sequence

We are given a bracket string, but it is not written explicitly character by character. Instead, it is compressed into blocks.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1556A - A Variety of Operations

We start with two integers, both initialized to zero. We are allowed to repeatedly apply operations that modify them using a freely chosen positive step size each time.

codeforcescompetitive-programmingmath
CF 1556B - Take Your Places!

We are given an array of integers, and we are allowed to swap adjacent elements. The goal is to rearrange the array so that no two neighboring elements share the same parity, meaning we want an alternating pattern of even and odd numbers.

codeforcescompetitive-programmingimplementation
CF 1555B - Two Tables

We are given a rectangular room and inside it a fixed axis-aligned rectangular table. The table currently occupies a block inside the room, but we are allowed to slide this table anywhere inside the room as long as it stays fully inside the boundary.

codeforcescompetitive-programmingbrute-force
CF 1555E - Boring Segments

We are given a set of weighted intervals on a number line from 1 to m. Each interval allows free movement between any two integer points inside it, which effectively means that once we pick a set of intervals, all points covered by overlapping intervals become connected…

codeforcescompetitive-programmingdata-structuressortingstreestwo-pointers
CF 1555A - PizzaForces

We are asked to build an order of pizzas where each pizza contributes both a fixed number of slices and a fixed baking time.

codeforcescompetitive-programmingbrute-forcemath
CF 1555D - Say No to Palindromes

We are given a string made only of three possible letters. For any substring, we are allowed to change characters, and each change replaces a character with any of the three letters.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpstrings
CF 1554B - Cobb

We are given an array of values indexed from one, and we want to choose two different positions in this array. For any chosen pair of indices, we compute a score made of two competing parts: a positive term that grows with the product of the indices, and a penalty term that…

codeforcescompetitive-programmingbitmasksbrute-forcegreedymath
CF 1553I - Stairs

We are given an array a of length n. It is not a permutation itself but a derived “stability profile” of an unknown permutation of 1..n. For each position i in that hidden permutation, we look at all subarrays that contain i.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpfftmath
CF 1553A - Digits Sum

We are given several independent queries. Each query provides a positive integer $n$, and we must count how many integers $x$ in the range from 1 to $n$ have a special property. For a number $x$, we compare the sum of its digits before and after adding one.

codeforcescompetitive-programmingmathnumber-theory
CF 1552F - Telepanting

We are simulating a point moving on a number line. The point starts at position 0 and moves strictly to the right at unit speed, so without any interruptions it would simply take $t$ seconds to reach position $t$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpsortings
CF 1552A - Subsequence Permutation

We are given a string made of lowercase letters. In one move, we are allowed to pick exactly one subset of positions, take the characters at those positions, and rearrange only those chosen characters arbitrarily while keeping all other characters fixed in their original places.

codeforcescompetitive-programmingsortingsstrings
CF 1551F - Equidistant Vertices

The task is about selecting a subset of vertices in a tree such that every pair of chosen vertices is equally far apart.

codeforcescompetitive-programmingbrute-forcecombinatoricsdfs-and-similardptrees
CF 1551D2 - Domino (hard version)

We are given a rectangular grid with $n$ rows and $m$ columns, and we must tile it completely using dominoes, each covering exactly two adjacent cells. Every cell must belong to exactly one domino, so the grid is fully partitioned into pairs of neighbors.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1551B2 - Wonderful Coloring - 2

We are given several test cases. In each case there is a sequence of integers and a number of colors. We want to “paint” some occurrences of these integers using up to $k$ colors, with the option to leave elements unpainted. The constraints inside the coloring are subtle.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedy
CF 1551C - Interesting Story

We are given several independent test cases. In each test case, we receive a list of words, and we want to select as many of these words as possible so that the selected subset satisfies a specific imbalance condition.

codeforcescompetitive-programminggreedysortingsstrings
CF 1550C - Manhattan Subarrays

We are given an array where each element represents a point on a vertical line at its index. More precisely, the i-th element forms a point $(ai, i)$ in a 2D plane. The distance between two points is measured using Manhattan distance.

codeforcescompetitive-programmingbrute-forcegeometrygreedyimplementation
CF 1550E - Stringforces

We are given a string made of lowercase letters from a small alphabet of size $k$, plus wildcard characters that can be replaced freely.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedpstringstwo-pointers
CF 1550F - Jumping Around

We are given a sorted set of points on a number line, which we can think of as rocks placed at distinct integer coordinates. A frog starts on one designated rock and can repeatedly jump to other rocks.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdpdsugraphsshortest-paths
CF 1550D - Excellent Arrays

We are given an array of length $n$, and each position $i$ must store an integer $ai$ within a fixed interval $[l, r]$. Two constraints define what makes a valid configuration interesting.

codeforcescompetitive-programmingbinary-searchcombinatoricsconstructive-algorithmsimplementationmathsortingstwo-pointers
CF 1550A - Find The Array

We are asked to construct an array of positive integers whose elements sum to a fixed value, while keeping the array as small as possible in length.

codeforcescompetitive-programminggreedymath
CF 1549B - Gregor and the Pawn Game

We are given a square board of size $n times n$, but only the first and last rows matter. The bottom row contains Gregor’s pawns, and the top row contains enemy pawns. Every column is either empty or occupied independently in those two rows.

codeforcescompetitive-programmingdfs-and-similardpflowsgraph-matchingsgraphsgreedyimplementation
CF 1549A - Gregor and Cryptography

We are given a prime number $P$, and for each test case we must output two integers $a$ and $b$ such that both lie between 2 and $P$, with $a < b$, and the remainders when dividing $P$ by $a$ and by $b$ are equal.

codeforcescompetitive-programmingmathnumber-theory
CF 1548E - Gregor and the Two Painters

The ceiling is split into a grid where each row contributes a fixed amount of paint and each column contributes another fixed amount. This makes every cell’s paint level completely determined by two arrays: one attached to rows and one attached to columns.

codeforcescompetitive-programmingdata-structuresdivide-and-conquergraphsgreedymath