brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2121B - Above the Clouds

We are asked to determine, for a given string, whether it is possible to split it into three non-empty parts, $a$, $b$, and $c$, such that $a + b + c = s$ and the middle segment $b$ appears as a substring of the concatenation $a + c$.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 2121A - Letter Home

We are given a set of distinct integer positions on the number line and a starting position. From the starting position, we can move left or right by one unit at a time.

codeforcescompetitive-programmingbrute-forcemath
CF 2122F - Colorful Polygon

We are given a small array of integers $a = [a1, a2, dots, an]$, with $n le 8$ and a total sum $S = a1 + dots + an le 100$.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquergeometry
CF 2122G - Tree Parking

We are asked to count valid parking schedules for cars on a tree. Each vertex of the tree will eventually host one car.

codeforcescompetitive-programmingcombinatoricsfftmathtrees
CF 2122E - Greedy Grid Counting

We are given a $2 times n$ grid with some cells already filled with integers between $1$ and $k$, while other cells are empty.

codeforcescompetitive-programmingcombinatoricsdpgreedymath
CF 2122B - Pile Shuffling

We are given several piles of tiles, each containing some zeros stacked on top of ones. For each pile, we know both the initial configuration and the target configuration, where the target also consists of some zeros on top of some ones.

codeforcescompetitive-programminggreedymath
CF 2122D - Traffic Lights

The problem describes a connected, simple undirected graph with n vertices and m edges. A token starts at vertex 1 at time 0. At each integer second t, if the token is at vertex u, you have two choices: either wait one second at u, or move along a specific edge of u.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpgraphsgreedyshortest-paths
CF 2122C - Manhattan Pairs

We are given a set of points on a 2D plane, and the number of points is always even. Our task is to pair all points into disjoint pairs such that the sum of Manhattan distances between the points in each pair is maximized.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedymathsortings
CF 2122A - Greedy Grid

We are working on a grid where each cell contains a nonnegative number, and we are only allowed to move either right or down starting from the top-left corner. Any such path from the top-left to the bottom-right has a total score equal to the sum of all visited cells.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2123F - Minimize Fixed Points

We are asked to construct a permutation of integers from $1$ to $n$ such that for every position $i$ from $2$ to $n$, the greatest common divisor of the position and its value, $gcd(pi, i)$, is strictly greater than $1$.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
Kvant Math Problem 276

A direct synthetic approach would require tracking the foot of a perpendicular from $B$ to the line $PC$, which suggests that a coordinate representation or vector projection will likely reduce the co…

kvantmathematicsolympiad
CF 2123G - Modular Sorting

We are maintaining an array that changes over time, and we are asked to answer two kinds of queries. One type permanently updates a single position in the array.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathnumber-theorysortings
CF 2123D - Binary String Battle

We are given a binary string. Two players alternate moves, with Alice moving first. The game evolves by repeatedly rewriting parts of the string.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 2123E - MEX Count

We are given an array of nonnegative integers, and we are asked to compute the number of distinct possible values of the minimum excluded value (MEX) after removing exactly $k$ elements from the array, for each $k$ from 0 to $n$.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingstwo-pointers
CF 2123B - Tournament

We have a tournament with n players. Player i has strength a[i]. Repeatedly, two surviving players are selected, and the weaker one is eliminated. If both strengths are equal, either one may be eliminated. The process stops when exactly k players remain.

codeforcescompetitive-programminggreedy
CF 2123A - Blackboard Game

The blackboard initially contains every integer from 0 to n - 1. A round always has two moves. First Alice removes some number a. Then Bob must remove a different number b such that $$a+b equiv 3 pmod 4.$$ If Bob cannot find such a number, the game ends immediately and Bob loses.

codeforcescompetitive-programmingmath
CF 2123C - Prefix Min and Suffix Max

We are given an array of distinct integers and a set of operations: you can either replace a prefix with its minimum or a suffix with its maximum.

codeforcescompetitive-programmingbrute-forcedata-structures
CF 2124I - Lexicographic Partition

Codeforces 2124I: Lexicographic Partition

codeforcescompetitive-programmingconstructive-algorithmsmathtrees
CF 2124H - Longest Good Subsequence

We are given an array a. We want to choose a subsequence and reinterpret it as a new array b. The goal is to maximize the length of b, subject to b being a good array. The definition of goodness is written in terms of a permutation and range minimums.

codeforcescompetitive-programmingdpmathtrees
CF 2124F2 - Appending Permutations (Hard Version)

We are building an array of length $n$, but we are not constructing it element by element. Instead, the array is formed by repeatedly appending whole blocks. Each block is a cyclic rotation of the permutation $[1, 2, ldots, s]$ for some chosen length $s$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2124G - Maximise Sum

I can't honestly produce a correct "complete solution editorial" for Codeforces 2124G from the information available here.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 2124D - Make a Palindrome

We start with an array and may repeatedly delete elements. The deletion rule is unusual: choose any subarray of length at least k, find its k-th smallest value, and delete one occurrence of that value inside the chosen subarray.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 2124F1 - Appending Permutations (Easy Version)

We are asked to count arrays of length $n$ that can be built by repeatedly appending cyclic shifts of the arrays $[1, 2, dots, s]$ for any $s ge 1$, while respecting a set of restrictions of the form $ai ne x$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2124E - Make it Zero

We are given an array of positive integers, and our only allowed action is to repeatedly subtract a carefully chosen auxiliary array from it.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2124A - Deranged Deletions

We are given an array and may delete any number of elements while preserving the relative order of the remaining ones. After the deletions, the remaining sequence must be non-empty.

codeforcescompetitive-programminggreedysortings
CF 2124B - Minimise Sum

We are given an array and we repeatedly look at prefix minimums: at position 1 we take the minimum of the first element, at position 2 we take the minimum over the first two elements, and so on until the full prefix. The final value is the sum of all these prefix minima.

codeforcescompetitive-programminggreedy
CF 2124C - Subset Multiplication

We are given an array b that was generated from an unknown “beautiful” array a, where each element divides the next. Bob then chose an integer x and multiplied some subset of a’s elements by x to form b. Our task is to recover any valid x.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 2125F - Timofey and Docker

Timofey has written a text s and wants to present it to a conference audience. Each attendee understands the topic if the number of times the substring "docker" appears consecutively in s falls within their personal interval [li, ri].

codeforcescompetitive-programmingbinary-searchdivide-and-conquerdp
CF 2125E - Sets of Complementary Sums

The problem asks us to count sets of integers that can be generated as complementary sums from some array of positive integers.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathtwo-pointers
CF 2125D - Segments Covering

We are working with a line of $m$ cells. Each cell must end up being covered by exactly one chosen interval. There are $n$ candidate segments. Each segment $i$ covers a contiguous range $[li, ri]$, but it is not guaranteed to exist.

codeforcescompetitive-programmingdpmathprobabilities
CF 2125A - Difficult Contest

We are given several strings consisting of uppercase letters. Each letter represents a contest problem. A contest is considered difficult if the string contains either "FFT" or "NTT" as a contiguous substring. We may rearrange the letters of the string in any order.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortingsstrings
CF 2125C - Count Good Numbers

A number is called good if none of the primes in its prime factorization are single digit primes. The only single digit primes are 2, 3, 5, and 7, so a number is good exactly when it is not divisible by any of these four primes.

codeforcescompetitive-programmingbitmaskscombinatoricsmathnumber-theory
CF 2125B - Left and Down

We start with a robot placed at a coordinate $(a,b)$ on an infinite grid, and we want to move it back to the origin $(0,0)$.

codeforcescompetitive-programmingmathnumber-theory
CF 2126G2 - Big Wins! (hard version)

We are given an array of integers, each between 1 and $n$, and we need to choose a contiguous subarray that maximizes the difference between its median and its minimum element.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdsutreestwo-pointers
CF 2126G1 - Big Wins! (easy version)

We are asked to find, for each array, a contiguous segment whose median minus its minimum is as large as possible. Formally, for a subarray $a[l, r]$, we calculate the median of its elements after sorting, then subtract the smallest element in that segment.

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsutwo-pointers
CF 2126F - 1-1-1, Free Tree!

We are given a tree where every vertex has a color and every edge has a weight. An edge contributes its weight to the total cost only when its endpoints currently have different colors; if the endpoints share the same color, the edge contributes nothing. The process is dynamic.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similargraphsimplementationtrees
CF 2126E - G-C-D, Unlucky!

We are given two arrays of integers, p and s, each of length n. Array p represents the prefix GCDs of some unknown array a, and array s represents the suffix GCDs of the same array. The task is to decide whether such an array a exists.

codeforcescompetitive-programmingmathnumber-theory
CF 2126D - This Is the Last Time

We are given a sequence of casinos, each defined by a range of coins [li, ri] that we must have to play, and a fixed result reali that becomes our new coin count after playing there. We start with k coins and can visit casinos in any order, but only once each.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 2126B - No Casino in the Mountains

We are given a sequence of days, each labeled either as rainy (1) or good (0). Jean wants to complete as many hikes as possible. Each hike takes exactly k consecutive days of good weather, and after finishing a hike, he must rest for at least one day before starting another.

codeforcescompetitive-programmingdpgreedy
CF 2126A - Only One Digit

The task asks us to find the smallest non-negative integer that shares at least one decimal digit with a given number. For every test case, we are provided a number x, and we need to produce a number y such that some digit in y also appears in x.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 2127H - 23 Rises Again

We are given an undirected, connected graph with up to 30 vertices, where each vertex belongs to at most 5 simple cycles. A simple cycle here is a closed path where each vertex has exactly two neighbors.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpflowsgraph-matchingsgraphsgreedyimplementationprobabilitiestrees
CF 2128C - Leftmost Below

We start with an array of length n, filled with zeros. An operation chooses a positive integer x that is strictly larger than the current minimum value in the array. The operation does not let us choose which position receives the increment.

codeforcescompetitive-programminggreedymath
CF 2128A - Recycling Center

We are given several independent scenarios. In each scenario there is a collection of bags, each with an initial weight. Time proceeds in discrete seconds. At every second we are forced to remove exactly one remaining bag.

codeforcescompetitive-programminggreedysortings
CF 2129F2 - Top-K Tracker (Hard Version)

We are given a hidden permutation of integers from 1 to $n$, and we can only access it indirectly through interactive queries. There are four types of queries.

codeforcescompetitive-programminginteractive
CF 2129F1 - Top-K Tracker (Easy Version)

We are asked to recover a hidden permutation of the numbers from 1 to $n$ through a limited set of interactive queries.

codeforcescompetitive-programminginteractive
CF 2129C3 - Interactive RBS (Hard Version)

We are given a hidden binary string made of opening and closing brackets, and we are allowed to probe it indirectly.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsdpinteractive
CF 2129E - Induced Subgraph Queries

We are given a simple undirected graph whose vertices are labeled from 1 to n. The label itself is also the index of the vertex. The graph does not change, but each query focuses only on a contiguous segment of vertices, from l to r.

codeforcescompetitive-programmingdata-structuresgraphssortings
CF 2129D - Permutation Blackhole

We are given a permutation of numbers from 1 to $n$, and a process that colors these numbers one by one in the order of the permutation. Each cell starts white with a score of zero.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpimplementationmath
CF 2129C2 - Interactive RBS (Medium Version)

We are given a hidden string made only of opening and closing parentheses. We cannot see it directly. Instead, we can query any multiset-like sequence of indices, and the judge constructs a new string by taking the characters at those indices in order.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2129C1 - Interactive RBS (Easy Version)

We are given a hidden bracket sequence of length $n$, consisting only of '(' and ')'. The goal is to reconstruct this sequence by asking at most 550 interactive queries.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2129B - Stay or Mirror

We are given a permutation of integers from 1 to n. For each element in this permutation, we are allowed to either leave it as-is or replace it with its “mirror” with respect to 2n, defined as $2n - pi$.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 2129A - Double Perspective

We are given a collection of segments on a line, each segment also acting as an edge between two vertices. From this set we must choose some subset of edges. Two different quantities are computed from the chosen subset.

codeforcescompetitive-programmingconstructive-algorithmsdpdsugraphsgreedysortings
CF 2130A - Submission is All You Need

We are given a multiset of non-negative integers, which we can think of as a bag of numbered tiles. Our goal is to repeatedly choose subsets of tiles and increase a score using one of two rules: either add the sum of the chosen tiles to the score, or add the minimum excluded…

codeforcescompetitive-programminggreedymath
CF 2131G - Wafu!

We start with a finite set of distinct positive integers. A single move depends entirely on the current minimum element of the set.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdfs-and-similardpmath
CF 2131H - Sea, You & copriMe

The problem gives us an array of integers, each between 1 and some upper bound $m$, and asks us to find four distinct indices $p, q, r, s$ such that the pair $(ap, aq)$ and the pair $(ar, as)$ are both coprime.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsgreedymathnumber-theory
CF 2131F - Unjust Binary Life

We are given two binary strings, a and b, each of length n. They define a virtual n × n grid where each cell (i, j) contains the value a[i] XOR b[j]. Yuri starts at the top-left cell (1,1) and can only move either right or down.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymathsortingstwo-pointers
CF 2131E - Adjacent XOR

We are given two arrays, a and b, both of length n. We can perform an operation on a at most once per index: for any index i from 1 to n-1, we can set a[i] to a[i] XOR a[i+1].

codeforcescompetitive-programmingbrute-forcegreedy
CF 2131D - Arboris Contractio

We are given a tree, an undirected connected graph with no cycles. Kagari can perform an operation that "re-roots" a path: choose two vertices, remove the edges along the path connecting them, and then reconnect all vertices along that path directly to the starting vertex.

codeforcescompetitive-programmingdata-structuresgraphsgreedytrees
CF 2131B - Alternating Series

We need to construct an integer array of length n with two properties. The first property says neighboring elements must always have opposite signs. Since their product must be negative, neither element can be zero, and the signs must alternate.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2131C - Make it Equal

We start with a multiset $S$ of size $n$ and we want to transform it into another multiset $T$ of the same size. The only allowed move takes one element $x$ from $S$, deletes it, and replaces it with either $x+k$ or $ The core question is whether repeated applications of these…

codeforcescompetitive-programmingmathnumber-theory
CF 2131A - Lever

We are given two arrays of equal length, a and b, and a machine called The Lever that iterates a process in which it adjusts the elements of a toward the elements of b.

codeforcescompetitive-programmingmath
CF 2132G - Famous Choreographer

We are given a rectangular grid of ballerinas, each performing one of 26 possible movements represented by lowercase English letters. Conceptually, each row is a string, and the entire grid is an array of strings.

codeforcescompetitive-programminghashingimplementationstrings
CF 2132F - Rada and the Chamomile Valley

We are asked to analyze a connected undirected graph representing the Chamomile Valley, where nodes are houses and edges are lanes between them. Rada wants to know which lanes are guaranteed to be part of every shortest path from house 1 to house n.

codeforcescompetitive-programmingdfs-and-similargraphsshortest-paths
CF 2132C2 - The Cunning Seller (hard version)

Each deal lets us buy exactly $3^x$ watermelons for $$3^{x+1} + x cdot 3^{x-1}$$ coins. We need to buy exactly $n$ watermelons. We may use at most $k$ deals. Among all valid ways to do that, we want the minimum total cost.

codeforcescompetitive-programmingbinary-searchgreedymath
CF 2132E - Arithmetics Competition

The problem presents a team of two players, Vadim and Kostya, who each have a collection of cards with numeric values.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingsternary-search
CF 2132D - From 1 to Infinity

We are asked to consider an infinite string formed by writing all positive integers consecutively: 123456789101112... and so on. For each test case, we are given a number k representing the number of digits to take from the start of this infinite string.

codeforcescompetitive-programmingbinary-searchdpimplementationmath
CF 2132A - Homework

We start with a string a. Another string b contains characters that must be inserted one by one, in the order they appear. For every position i in b, the corresponding character c[i] tells us who inserts that character.

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 2132B - The Secret Number

We are given a number $n$ that was constructed in a very specific way. Someone secretly chose an integer $x$, then created another number $y$ by appending one or more zeros to the right of $x$. That means $y = x cdot 10^k$ for some $k ge 1$.

codeforcescompetitive-programmingmath
CF 2132C1 - The Cunning Seller (easy version)

The problem gives us a seller who offers watermelons in bundles of sizes that are powers of three. Each bundle of size $3^x$ costs $3^{x+1} + x cdot 3^{x-1}$ coins.

codeforcescompetitive-programminggreedymath
CF 2133D - Chicken Jockey

Working

codeforcescompetitive-programmingdpgreedy
CF 2133E - I Yearned For The Mines

We are working on a tree where an adversary occupies exactly one node, but we never know which one. The adversary is also reactive: after each of our actions, they are allowed to move along one edge or stay in place, except in the special case where we directly queried their…

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgreedytrees
CF 2133F - Flint and Steel

We are given a line of creepers, each with an explosive power. Detonating a creeper at position $i$ kills all creepers within distance less than its explosive power, specifically positions $j$ such that $ The input consists of multiple test cases, each with $n$ creepers and an…

codeforcescompetitive-programmingdata-structuresdpgraphs
CF 2133C - The Nether

We are given a network of nether portals represented as a directed acyclic graph. Each portal may have directed connections to other portals, but there are no cycles. The task is to find a longest path in this hidden DAG.

codeforcescompetitive-programminggraphsinteractive
CF 2133B - Villagers

We are given several independent scenarios. In each scenario, there are $n$ villagers, and each villager starts with a non-negative integer value called grumpiness.

codeforcescompetitive-programminggreedy
CF 2133A - Redstone?

We are asked to decide whether a sequence of gears can be arranged in a line such that spinning the leftmost gear at one revolution per second results in the rightmost gear spinning exactly at one revolution per second.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmath
CF 2134D - Sliding Tree

We are given a tree and a very specific local rewiring operation. The operation picks a vertex $b$ with two distinguished neighbors $a$ and $c$. After that, every other neighbor of $b$ is detached from $b$ and reattached to $c$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedyimplementationtrees
CF 2134E - Power Boxes

We are given a sequence of boxes, each with a hidden power of either 1 or 2. The boxes are placed on a number line at positions 1 through n. We need to discover the power of each box using two interactive queries: swapping adjacent boxes and throwing a ball at a box.

codeforcescompetitive-programmingconstructive-algorithmsdpimplementationinteractive
CF 2134F - Permutation Oddness

We are given counts for four integers, 0 through 3. Specifically, $c0$ copies of 0, $c1$ copies of 1, $c2$ copies of 2, and $c3$ copies of 3. From this, we can form an array of length $n = c0 + c1 + c2 + c3$.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2134C - Even Larger

We are given an array of non-negative integers and we need to make it good by performing the minimum number of operations.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 2134A - Painting With Two Colors

We are given a row of n cells, all initially white. We have two painting operations. The first operation paints a consecutive cells red, starting at any position x such that the red block fits entirely within the row.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 2134B - Add 0 or K

We are given an array of positive integers and a positive integer $k$. For each element of the array, we are allowed to either leave it as-is or add $k$ to it in one operation.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 2135F - To the Infinity

We are given a rooted full binary tree where every node represents a function built recursively from its children. Leaves behave simply: their function is just the identity map $fu(x) = x$.

codeforcescompetitive-programmingdata-structureshashingmathtrees
CF 2135E2 - Beyond the Palindrome (Hard Version)

We are asked to count binary strings of a given length that are almost-palindromes under a specific transformation. For a binary string, repeatedly deleting all occurrences of the substring 10 yields a "reduced" string.

codeforcescompetitive-programmingcombinatoricsdpmathnumber-theory
CF 2135D2 - From the Unknown (Hard Version)

The task is to determine the unknown width parameter $W$ of a text editor. The editor displays a sequence of words, each represented by its length, on lines of width $W$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsinteractivemath
CF 2135E1 - Beyond the Palindrome (Easy Version)

We are asked to count a specific subset of binary strings of length $n$, which are called almost-palindromes. The key to understanding this problem is the function $f(r)$, which repeatedly deletes all occurrences of the substring 10 from a binary string $r$ until no 10 remains.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2135D1 - From the Unknown (Easy Version)

We are trying to determine an unknown integer parameter $W$, the width of lines in a text editor. Each article we submit is a sequence of positive integers representing word lengths.

codeforcescompetitive-programmingconstructive-algorithmsinteractivemath
CF 2135A - Against the Difference

We are given an array of integers, and we want to find the length of the longest subsequence that can be split into "blocks". A block is defined as a contiguous sequence where every element equals the length of that sequence.

codeforcescompetitive-programmingdata-structuresdp
CF 2135C - By the Assignment

We are given a connected undirected graph where each vertex may have a weight, but some weights are missing and represented by -1. The goal is to fill in the missing weights such that the graph becomes balanced.

codeforcescompetitive-programmingbinary-searchbitmaskscombinatoricsdfs-and-similardsugraphsmath
CF 2135B - For the Champion

The original problem is interactive. We know a set of anchor points, and there is a hidden robot position. By moving the robot and observing the minimum Manhattan distance to any anchor, we must recover the initial coordinates.

codeforcescompetitive-programmingconstructive-algorithmsinteractivemath
CF 2136A - In the Dream

We know the score at halftime and the score at full time. If the halftime score is a:b, then during the first half the RiOI team scored exactly a goals and the KDOI team scored exactly b goals.

codeforcescompetitive-programminggreedymath
CF 2137G - Cry Me a River

We are given a directed acyclic graph with n nodes and m edges. Each node starts colored blue, and players Cry and River play a two-player token game. The token starts at a node s. Cry moves first, then River, and they alternate.

codeforcescompetitive-programmingdfs-and-similardpgamesgraphs
CF 2137D - Replace with Occurrences

We are given a sequence of numbers, and we want to interpret each number in that sequence as a frequency requirement for some unknown array we must construct.

codeforcescompetitive-programmingconstructive-algorithms
CF 2137F - Prefix Maximum Invariance

For any array $x$, its sequence of prefix maxima is completely determined. At position $i$, the prefix maximum is $$max(x1,x2,dots,xi).$$ We are allowed to build another array $z$ whose prefix maxima are identical to those of $x$.

codeforcescompetitive-programmingbinary-searchcombinatoricsdata-structuressortings
CF 2137E - Mexification

We are given an array of integers and asked to perform a special transformation multiple times. For each element in the array, we replace it with the minimum non-negative integer that does not appear anywhere else in the array.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 2137A - Collatz Conjecture

We are given the result of running the Collatz operation exactly k times and the final value x. The task is not to find the original value uniquely, because many different starting values may lead to the same result.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2137C - Maximum Even Sum

We are given two integers, $a$ and $b$, and we can pick a positive integer $k$ such that $b$ is divisible by $k$. Then we replace $a$ with $a cdot k$ and $b$ with $b / k$. The goal is to make the sum $a + b$ as large as possible while ensuring it is even.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 2137B - Fun Permutation

We are given a permutation $p$ of size $n$, meaning it contains each integer from $1$ to $n$ exactly once. We must construct another permutation $q$ of the same size, also a rearrangement of $1$ to $n$, with a structural constraint linking adjacent positions.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 2138F - Ode to the Bridge Builder

We start with two fixed points in the plane, one at the origin and one at $(1,0)$, connected by a segment. The only allowed way to create new points is by repeatedly selecting an existing segment, treating its endpoints as two vertices of a triangle, and then placing a third…

codeforcescompetitive-programmingconstructive-algorithmsgeometry
CF 2138E2 - Determinant Construction (Hard Version)

We are asked to construct a square matrix with small integer entries, limited non-zero elements per row and column, and a determinant equal to a given target number.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathmatricesnumber-theory
CF 2138E1 - Determinant Construction (Easy Version)

The determinant can be written using the Leibniz formula: $$det(M)=sum{sigma} operatorname{sgn}(sigma)prodi M{i,sigma(i)}.$$ A brute force viewpoint is to think of each permutation as choosing one outgoing edge from every row and one incoming edge into every column.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathmatricesnumber-theory