brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1691E - Number of Groups

We are given a set of segments on the number line, each colored either red or blue. Each segment occupies a continuous interval from li to ri, inclusive.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedysortings
CF 1691D - Max GEQ Sum

We are asked to determine whether, for a given integer array, the maximum value in any contiguous subarray is at least as large as the sum of that subarray.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdivide-and-conquerimplementationtwo-pointers
CF 1691B - Shoe Shuffling

We are given a sorted list of shoe sizes for a group of students. Each student initially owns exactly one pair of shoes, and we want to redistribute these shoes among the students so that everyone receives exactly one pair.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationtwo-pointers
CF 1691A - Beat The Odds

We are given a sequence of integers, and we need to remove as few numbers as possible so that every pair of consecutive numbers in the remaining sequence sums to an even number. The sum of two numbers is even if both numbers are even or both are odd.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1692H - Gambling

We know the outcomes of the next $n$ dice rolls in advance. Marian chooses a value $a$, and a contiguous segment of rounds $[l,r]$. During every round in that segment he always guesses the same value $a$. Whenever the actual rolled value equals $a$, his money doubles.

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 1692G - 2^Sort

We are given an array and asked to examine every contiguous segment of fixed length $k+1$. For each such segment starting at position $i$, we conceptually transform it by multiplying element $j$ (relative to the segment start) by $2^j$.

codeforcescompetitive-programmingdata-structuresdpsortingstwo-pointers
CF 1692D - The Clock

We are given a starting time on a 24-hour clock and a fixed number of minutes between observations. Starting from the given time, Victor repeatedly looks at the clock after every $x$ minutes.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1692F - 3SUM

We are given an array of positive integers, and we want to know if we can select three distinct elements whose sum ends with the digit 3. In other words, if we denote the chosen elements as $ai$, $aj$, and $ak$, then $(ai + aj + ak) mod 10 = 3$.

codeforcescompetitive-programmingbrute-forcemath
CF 1692E - Binary Deque

We are given a binary array of length $n$, meaning each element is either 0 or 1. The task is to perform a sequence of operations where, in each operation, we remove either the first or the last element of the array.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
CF 1692B - All Distinct

We are given an array of integers. In one operation, we must remove exactly two elements from the array. The two removed elements can be any values, as long as they come from different positions.

codeforcescompetitive-programminggreedysortings
CF 1692A - Marathon

We are asked to determine Timur's position relative to three other runners in a marathon. Each test case provides four distinct integers: Timur's distance first, followed by the distances run by three other participants.

codeforcescompetitive-programmingimplementation
CF 1692C - Where's the Bishop?

The discrepancy is not caused by a small implementation bug. The outputs show that the algorithm itself is overcounting the cost of independent intervals.

codeforcescompetitive-programmingimplementation
CF 1693F - I Might Be Wrong

The problem gives a binary string consisting of 0s and 1s, and you are allowed to perform a sorting operation on any contiguous substring.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1693E - Outermost Maximums

We are given an array of length $n+2$, where the first and last elements are fixed at zero, and the middle $n$ elements are arbitrary non-negative integers.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1693D - Decinc Dividing

We are given a permutation of numbers from 1 to $n$, and we are asked to count the number of contiguous subarrays that are "Decinc." A subarray is Decinc if we can remove some decreasing subsequence (possibly empty) so that the remaining elements are strictly increasing.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpgreedy
CF 1693A - Directional Increase

The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.

codeforcescompetitive-programminggreedy
CF 1693B - Fake Plastic Trees

We are given a rooted tree. Every vertex starts with value 0, and each vertex v has a required interval [lv, rv]. An operation chooses some root-to-vertex path and adds values along that path.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1693C - Keshi in Search of AmShZ

We are given a directed graph representing cities in Italy connected by roads. Keshi starts in city 1 and wants to reach city n, where AmShZ is waiting. Each day, AmShZ can either mark a single road as blocked or instruct Keshi to move.

codeforcescompetitive-programminggraphsgreedyshortest-paths
CF 1694A - Creep

The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.

codeforcescompetitive-programminggreedyimplementation
CF 1694B - Paranoid String

We are asked to count substrings of a binary string that are "paranoid." A paranoid string is one that can be reduced to a single character by repeatedly applying two operations: replacing 01 with 1 or 10 with 0.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1695E - Ambiguous Dominoes

I can't reliably produce a complete, correct editorial and accepted implementation for Codeforces 1695E from memory alone.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphs
CF 1695D1 - Tree Queries (Easy Version)

We are asked to determine the minimum number of distance queries required to uniquely identify a hidden vertex in a tree. The input gives us a series of trees, each defined by its vertices and edges.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardpgreedytrees
CF 1695D2 - Tree Queries (Hard Version)

We are given an unrooted tree with $n$ vertices. There is a hidden vertex $x$ that we need to identify. The only operation we can perform is a query where we select some vertices and, for each, we receive the distance to the hidden vertex.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgreedytrees
CF 1695C - Zero Path

We have a grid whose cells contain only 1 or -1. Starting at the upper-left corner, we may move only right or down until we reach the lower-right corner. Every visited cell contributes its value to the path sum. The task is not to find the number of such paths or the minimum sum.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgraphsgreedyshortest-paths
CF 1695A - Subrectangle Guess

We are given a grid containing distinct integers. Michael chooses dimensions h × w, then Joe secretly selects any subrectangle of exactly that size. Michael must name the maximum value inside Joe's chosen rectangle before seeing which rectangle was selected.

codeforcescompetitive-programminggames
CF 1695B - Circle Game

We are asked to analyze a two-player game played on a circle of stone piles. Each pile has a certain number of stones. Players take turns removing a positive number of stones from the current pile.

codeforcescompetitive-programminggamesgreedy
CF 1696H - Maximum Product?

We are given a collection of integers where each element is tied to its index, so even equal values are treated as distinct items. From this collection, every subset is considered independently.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgreedyimplementationmathtwo-pointers
CF 1696C - Fishingprince Plays With Array

We are given two arrays and a fixed integer $m$. Starting from the first array, we may repeatedly split an element divisible by $m$ into $m$ equal pieces, or merge $m$ consecutive equal elements into one larger element.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1696G - Fishingprince Plays With Array Again

We are given an array whose values represent amounts that must be removed. An operation acts on one adjacent pair. If we spend $t$ seconds on edge $(i,i+1)$, we may subtract $(x t, y t)$ from the pair or $(y t, x t)$ from the pair.

codeforcescompetitive-programmingbrute-forcedata-structuresgeometrymath
CF 1696F - Tree Recovery

We are asked to reconstruct a tree based on a set of distance equalities between triples of vertices. Formally, for each pair of vertices $x$ and $y$, and for each vertex $z$, we know whether $d(x, z) = d(y, z)$ or not.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similardsugraphstrees
CF 1696D - Permutation Graph

We are given a permutation of integers from 1 to n and asked to construct a graph based on the relative minimum and maximum values in contiguous segments.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdivide-and-conquergreedyshortest-paths
CF 1696E - Placing Jinas

We are asked to control dolls on an infinite grid where each cell can be white or black. The color of each cell is defined by a non-increasing sequence $a0, a1, dots, an$, extended with zeros beyond $n$.

codeforcescompetitive-programmingcombinatoricsmath
CF 1696B - NIT Destroys the Universe

We are given an array representing the “universe,” where each element is a non-negative integer. The protagonist, NIT, can perform a specific operation on any contiguous subarray: compute the mex of that subarray and set every element in it to that mex.

codeforcescompetitive-programminggreedy
CF 1696A - NIT orz!

We are given an array of integers and a number $z$. We are allowed to repeatedly pick any element $ai$ and perform two bitwise operations: update $ai$ to $ai operatorname{or} z$ and simultaneously update $z$ to $ai operatorname{and} z$.

codeforcescompetitive-programmingbitmasksgreedy
CF 1697C - awoo's Favorite Problem

The problem gives two strings s and t of the same length consisting of the characters 'a', 'b', and 'c'. The allowed operations let us swap adjacent "ab" to "ba" and "bc" to "cb". The task is to determine whether we can transform s into t using any number of these moves.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedyimplementationstringstwo-pointers
CF 1697F - Too Many Constraints

We are asked to construct a sequence of integers of length n, where each element lies between 1 and k, and the sequence must be non-decreasing. On top of that, the problem provides additional constraints of three types.

codeforcescompetitive-programming2-satconstructive-algorithmsgraphsimplementation
CF 1697E - Coloring

We are given a set of points on a 2D plane with unique coordinates. Each point must be assigned a color represented by an integer from 1 to $n$, and the coloring must satisfy two distance-based constraints.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdpgeometrygraphsgreedyimplementationmath
CF 1697D - Guess The String

We are trying to reconstruct an unknown string of length $n$, where each position contains a lowercase letter. The only way to interact with this hidden string is through two operations: we can directly reveal the character at a chosen position, or we can query a segment and…

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive
CF 1697A - Parkway Walk

We are given a linear sequence of benches, numbered from one to $n+1$, separated by distances $a1, a2, dots, an$. You start at the first bench with a fixed amount of energy $m$. Walking a distance of one meter consumes exactly one unit of energy.

codeforcescompetitive-programminggreedyimplementation
CF 1697B - Promo

We have a store with n items, each with a specific price. The store runs a promotion where, if a customer buys at least x items, the y cheapest among those items are free. For each query (x, y), we want to determine the maximum total value of items a customer can get for free.

codeforcescompetitive-programminggreedysortings
CF 1698C - 3SUM Closure

We are asked to determine if an array of integers is 3SUM-closed, which means that for every triple of distinct elements in the array, the sum of those three elements is itself present somewhere in the array.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 1698G - Long Binary String

We are given a small binary string s of length up to 35, and we need to manipulate a conceptual binary string t of length $10^{100}$, which is initially all zeros. The operation allowed is selecting a contiguous substring of t of the same length as s and XOR-ing it with s.

codeforcescompetitive-programmingbitmasksmathmatricesmeet-in-the-middlenumber-theory
CF 1698F - Equal Reversal

We are given two arrays, a and b, each of length n. The array b is a permutation of a, so they contain the same multiset of values but possibly in a different order.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementationmath
CF 1698E - PermutationForces II

We start with a permutation a, which represents the initial ordering of 1..n. Over n steps, we are allowed to repeatedly swap elements, but the swap range grows in a constrained way: at step i, we can only operate on positions from i to min(i+s, n).

codeforcescompetitive-programmingbrute-forcecombinatoricsgreedysortingstreestwo-pointers
CF 1698D - Fixed Point Guessing

We start with a permutation of numbers from 1 to n, but the permutation is not arbitrary. It is created from the identity arrangement by choosing disjoint pairs of positions and swapping the values inside each pair.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractive
CF 1698A - XOR Mixup

We are given an array of length n that was generated by taking an original array of length n-1, computing the XOR of all its elements, appending that XOR to the array, and then shuffling the result.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1698B - Rising Sand

We are given a row of sand piles, each with some initial height. We are allowed to perform an operation that picks a contiguous segment of fixed length k and increases every pile in that segment by one unit. We can repeat this operation any number of times and on any segments.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1699B - Almost Ternary Matrix

We are asked to construct a binary matrix of size $n times m$ where $n$ and $m$ are guaranteed to be even. The constraint is that each cell must have exactly two neighbors with a value different from its own. Neighbors are defined as the four cells directly adjacent by side.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmatrices
CF 1699E - Three Days Grace

The problem gives us a multiset of integers, all bounded by a maximum value m, and allows us to repeatedly replace any number x 3 with two integers p and q such that pq = x and both p and q are greater than 1. After each operation, the multiset grows by one element.

codeforcescompetitive-programmingdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1699D - Almost Triple Deletions

We are given an array of integers, and we can repeatedly remove adjacent pairs that are different. After each removal, the array shrinks and its remaining elements shift left.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1699C - The Third Problem

We are given a permutation of integers from 0 to $n-1$, which is simply a rearrangement of these numbers with no repeats. The task is to count how many other permutations are "similar" to the given one, where similarity is defined through the MEX function.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1699A - The Third Three Number Problem

We are asked to construct three integers $a$, $b$, and $c$, each lying in a large range up to $10^9$, such that a specific expression involving pairwise XOR values matches a given target number $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1700E - Serega the Pirate

The puzzle is represented as an $n times m$ grid containing each integer from $1$ to $n cdot m$ exactly once. A sequence solves the puzzle if, when following a path of adjacent cells, the first time each number is visited respects the natural order $1, 2, dots, n cdot m$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1700D - River Locks

The system is a chain of containers, each with a fixed capacity. Water enters a selected subset of these containers at a constant rate of one unit per second per opened pipe.

codeforcescompetitive-programmingbinary-searchdpgreedymath
CF 1700F - Puzzle

We are given two binary grids, each with exactly two rows and $n$ columns. Every cell contains either a zero or a one. The grid starts in an initial configuration and must be transformed into a target configuration.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1700A - Optimal Path

We are asked to find the minimal cost for a turtle to travel from the top-left corner of a table to the bottom-right corner. The table has (n) rows and (m) columns, and each cell contains the number ((i-1) cdot m + j), where (i) and (j) are the row and column indices.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1700B - Palindromic Numbers

The proposed solution is for a Codeforces problem about counting “beautiful triples” in a dynamic set of points. However, the exercise cited, 3.4.1.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1700C - Helping the Nature

We have an array of integers representing soil moisture levels along a path of trees. Each value can be positive, negative, or zero, and our goal is to reduce all values to zero using three operations: decrease a prefix by one, decrease a suffix by one, or increase the entire…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1701F - Points

We are given a dynamic set of points on a number line and a fixed parameter $d$. A triple $(i,j,k)$ is called beautiful if the points satisfy $i < j < k$ and the distance between the endpoints $k - i$ is at most $d$. Initially the set of points is empty.

codeforcescompetitive-programmingcombinatoricsdata-structuresimplementationmathmatrices
CF 1701E - Text Editor

We are given two strings, s and t, representing the text we actually wrote and the text we want to have, respectively.

codeforcescompetitive-programmingbrute-forcedpgreedystrings
CF 1701A - Grass Field

We are given a tiny grass field of size $2 times 2$, where each cell either has grass (1) or is empty (0). The goal is to remove all grass using the fewest moves possible.

codeforcescompetitive-programmingimplementation
CF 1701C - Schedule Management

We are given a collection of tasks, where each task has a designated “preferred” worker. If a worker processes a task they are assigned to prefer, it takes one unit of time; otherwise it takes two.

codeforcescompetitive-programmingbinary-searchgreedyimplementationtwo-pointers
CF 1701B - Permutation

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1702G1 - Passable Paths (easy version)

We are given a tree and several queries. Each query specifies a set of vertices. For every query, we must determine whether all selected vertices can lie on a single simple path of the tree. A tree contains exactly one simple path between any two vertices.

codeforcescompetitive-programmingdfs-and-similartrees
CF 1702G2 - Passable Paths (hard version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingdata-structuresdfs-and-similartrees
CF 1702F - Equate Multisets

We are given two collections of integers of the same size. Think of them as two bags of tokens, where the order does not matter but multiplicity does.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedymathnumber-theory
CF 1702D - Not a Cheap String

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1702E - Split Into Two Sets

We are given a collection of dominoes, each domino represented as a pair of integers between 1 and n, and the total number of dominoes n is even. The task is to split these dominoes into two groups so that within each group no number appears on more than one domino.

codeforcescompetitive-programmingdfs-and-similardsugraphs
CF 1702C - Train and Queries

We are given a train route along stations with very large indices, from 1 to $10^9$. The train travels in the exact order of a list $u1, u2, dots, un$ and can revisit stations multiple times.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1702A - Round Down the Price

Each test case gives the current price of an item. A "round" price is any power of ten: 1, 10, 100, 1000, and so on. We want to reduce the item's price until it becomes the largest round number that does not exceed the original price.

codeforcescompetitive-programmingconstructive-algorithms
CF 1702B - Polycarp Writes a String from Memory

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programminggreedy
CF 1703G - Good Key, Bad Key

We are asked to open a sequence of chests, each containing some number of coins, using either “good” or “bad” keys.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedymath
CF 1703F - Yet Another Problem About Pairs Satisfying an Inequality

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedysortings
CF 1703E - Mirror Grid

We are given an $n times n$ grid whose cells contain only 0 or 1. We may flip any cell, changing 0 to 1 or 1 to 0, and each flip costs one operation. The goal is to make the grid look identical after rotating it by $90^circ$, $180^circ$, or $270^circ$.

codeforcescompetitive-programmingimplementation
CF 1703D - Double Strings

We are given a collection of short lowercase strings, each with length at most 8. For every string in the list, we need to decide whether it can be formed by taking two strings from the same list and concatenating them in order.

codeforcescompetitive-programmingbrute-forcedata-structuresstrings
CF 1703C - Cypher

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1703A - YES or YES?

We are asked to check whether a three-character string represents the word "YES", ignoring letter case. Each test case provides a single string, and we must output a uniform "YES" or "NO" for each one.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 1703B - ICPC Balloons

The contest system processes a sequence of problem solves in time order. Each character in the input string represents a problem label from A to Z, and each occurrence means some team solved that problem at that moment.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1704G - Mio and Lucky Array

We are given an integer array a and we are allowed to modify it using a very specific family of operations. Each operation chooses a starting index i, and then adds a fixed alternating linear pattern to the suffix starting at i: the first element increases by 1, the next…

codeforcescompetitive-programmingconstructive-algorithmsfftmathstrings
CF 1704H1 - Game of AI (easy version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpfftmath
CF 1704H2 - Game of AI (hard version)

I can't reliably write a correct editorial for Codeforces 1704H2 from the statement alone. This problem is a 3500-rated combinatorics/FFT problem, and the crucial part of a useful editorial is the exact combinatorial characterization, recurrence, generating-function derivation…

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1704F - Colouring Game

We are given a row of cells, each painted either red or blue. Alice and Bob take turns, starting with Alice. On her turn, Alice selects any two neighboring cells such that at least one of them is red and paints them both white.

codeforcescompetitive-programmingconstructive-algorithmsdpgames
CF 1704E - Count Seconds

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgraphsimplementationmath
CF 1704D - Magical Array

We are given several arrays of equal length. All of them originate from the same hidden base array. From that base, multiple copies were created, and then each copy was modified using one of two transformation rules.

codeforcescompetitive-programmingconstructive-algorithmshashingimplementationmath
CF 1704A - Two 0-1 Sequences

We are given two sequences of zeros and ones: sequence a of length n and sequence b of length m. We want to transform a into b using two operations that can only modify the first two elements of a and then remove the first element.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1704B - Luke is a Foodie

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1704C - Virus

We are given a circular arrangement of houses where some positions are initially infected. Each day consists of two phases: first, we permanently protect exactly one currently safe house, and then the infection spreads from every infected house to all adjacent unprotected and…

codeforcescompetitive-programminggreedyimplementationsortings
CF 1705F - Mark and the Online Exam

We are asked to recover the answer key for an online true/false exam with $n$ questions. Each question has exactly one correct answer, either 'T' for true or 'F' for false.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractiveprobabilities
CF 1705E - Mark and Professor Koro

We are given a multiset of positive integers that changes over time. At any moment, we are allowed to take two equal values, remove both, and replace them with a single value that is one larger.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcecombinatoricsdata-structuresgreedy
CF 1705D - Mark and Lightbulbs

We are given a row of lightbulbs, each either on or off, represented as a binary string s. Mark wants to transform this initial configuration into a target configuration t by repeatedly toggling bulbs under a restricted operation: he can choose any bulb i that is not the first…

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedymathsortings
CF 1705B - Mark the Dust Sweeper

We are given a row of rooms, each with some amount of dust. Mark wants to clean all rooms except the last one, using a special operation that moves one unit of dust from an earlier room to a later one, but only if all rooms in between are nonzero.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1705C - Mark and His Unfinished Essay

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1705A - Mark the Photographer

We have a total of $2n$ people with known heights. Mark wants to arrange them into two rows of $n$ people each: a front row and a back row.

codeforcescompetitive-programminggreedysortings
CF 1706E - Qpwoeirut and Vertices

We are given a connected undirected graph with $n$ vertices and $m$ edges. Each edge is numbered from 1 to $m$, and we are asked to process $q$ queries.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardivide-and-conquerdsugreedytrees
CF 1706D1 - Chopping Carrots (Easy Version)

Two constructions are proposed for generating a random variable $X$ with a nontrivial distribution on $[-1,1]$. The first maps a single uniform deviate through a trigonometric transformation.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedynumber-theory
CF 1706D2 - Chopping Carrots (Hard Version)

We are given a sorted array of integers representing carrot sizes and a limit k. Our goal is to assign to each carrot a number of cuts, represented by integers pi between 1 and k. Cutting a carrot ai into pi pieces produces a piece size of floor(ai / pi).

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresdpgreedymathnumber-theorytwo-pointers
CF 1706B - Making Towers

We are given a sequence of n blocks, each with a color from 1 to n. We need to place them one by one on a 2D grid. The first block always starts at (0, 0).

codeforcescompetitive-programmingdpgreedymath
CF 1706A - Another String Minimization Problem

We are asked to construct a string of length m, initially filled with the letter 'B', by performing n operations defined by a sequence a1, a2, ..., an.

codeforcescompetitive-programming2-satconstructive-algorithmsgreedystring-suffix-structuresstrings
CF 1706C - Qpwoeirut And The City

We are given a row of buildings, each with a certain number of floors. A building is considered "cool" if it is strictly taller than both its immediate neighbors. The first and last buildings cannot be cool because they do not have two neighbors.

codeforcescompetitive-programmingdpflowsgreedyimplementation
CF 1707E - Replace

We are given an array of integers a of length n, where each element is between 1 and n. Conceptually, imagine these as labeled tiles laid out in a row.

codeforcescompetitive-programmingbinary-searchdata-structures