brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 2039E - Shohag Loves Inversions

We are asked to count the number of distinct arrays of length $n$ that can be generated starting from the array $[0, 1]$ by repeatedly inserting the current inversion count anywhere in the array. An inversion is a pair of indices $(i, j)$ such that $i < j$ and $ai aj$.

codeforcescompetitive-programmingcombinatoricsdpimplementationmath
CF 2039C2 - Shohag Loves XOR (Hard Version)

We are asked to count integers $y$ in the range from 1 to $m$ such that $x oplus y$ is divisible by at least one of $x$ or $y$. Here, $oplus$ is the bitwise XOR operator.

codeforcescompetitive-programmingbitmasksbrute-forcemathnumber-theory
CF 2039A - Shohag Loves Mod

We need to construct an increasing sequence of length $n$, where every value lies between 1 and 100. The sequence must satisfy a special condition involving remainders. For each position $i$, consider the value $ai bmod i$.

codeforcescompetitive-programmingconstructive-algorithmsnumber-theory
CF 2039B - Shohag Loves Strings

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationstrings
CF 2039C1 - Shohag Loves XOR (Easy Version)

We are given a number $x$ and a very large upper bound $m$. For each test case, we must count how many integers $y$ in the range $1 le y le m$ satisfy a condition defined through XOR. For a candidate $y$, we compute $z = x oplus y$.

codeforcescompetitive-programmingbitmasksbrute-forcemathnumber-theory
CF 2040D - Non Prime Tree

We are given a tree with $n$ vertices, and we must assign each vertex a distinct integer from the range $1$ to $2n$, using exactly $n$ of those numbers. The assignment is arbitrary except that every vertex gets a unique value.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargreedynumber-theorytreestwo-pointers
CF 2040F - Number of Cubes

We have an $a times b times c$ toroidal grid of unit cubes. Each cell receives one of $k$ colors, and color $i$ must appear exactly $di$ times. Two colorings are considered the same if one can be transformed into the other by cyclic shifts along the three coordinate axes.

codeforcescompetitive-programmingcombinatoricsdpmathnumber-theory
CF 2040E - Control of Randomness

We are given a tree, an undirected connected acyclic graph, with n vertices rooted at vertex 1. A robot starts at some vertex v ≠ 1 and moves toward the root. Odd-numbered steps are deterministic: the robot always moves one step along a shortest path toward vertex 1.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgraphsgreedymathprobabilitiestrees
CF 2040B - Paint a Strip

Codeforces 2040B: Paint a Strip

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2040C - Ordered Permutations

We are asked to work with permutations of numbers from 1 to n, and each permutation has a sum defined by taking every contiguous subarray and adding its minimum. Among all permutations of length n, some permutations maximize this sum.

codeforcescompetitive-programmingbitmaskscombinatoricsconstructive-algorithmsgreedymathtwo-pointers
CF 2040A - Game of Division

We are looking at a decision problem where one player tries to “trap” another player using modular arithmetic on array values. We are given an array of integers. The first player picks a single position in the array and commits to that value.

codeforcescompetitive-programminggamesmath
Kvant Math Problem 679

Let the circles be $\omega_1,\omega_2,\omega_3,\omega_4$ with consecutive tangency points $A,B,C,D$.

kvantmathematicsolympiad
CF 2041N - Railway Construction

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programming
CF 2041M - Selection Sort

We are given a single array of integers, and we want to transform it into a non-decreasing sequence. The only tool allowed is a special sorting routine that behaves like a selection-sort variant: it repeatedly compares a fixed position with all later positions and swaps…

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 2041L - Building Castle

I can't provide a correct editorial for Codeforces 2041L from the problem statement alone because the key geometric optimization step is nontrivial, and I do not have enough information about the official solution to reconstruct a provably correct accepted algorithm.

codeforcescompetitive-programming
CF 2041J - Bottle Arrangement

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpdsugreedy
CF 2041I - Auto Complete

We are asked to simulate an advanced text editor that supports four operations: adding patterns for auto-complete, deleting patterns, appending text to the current editor content, and deleting characters from the end of the current content.

codeforcescompetitive-programmingbinary-searchdata-structureshashingimplementationsortingsstringstrees
CF 2041K - Trophic Balance Species

We are given an ecosystem modeled as a directed graph, where each node represents a species and each directed edge represents a feeding relationship from prey to predator. For each species, we want to identify whether it is a trophic balance species.

codeforcescompetitive-programmingbinary-searchbrute-forcedfs-and-similargraphs
CF 2041G - Grid Game

We have an enormous $n times n$ grid, where $n$ can be as large as $10^9$. Some cells are painted black by drawing vertical segments inside columns. Every cell covered by at least one segment becomes black.

codeforcescompetitive-programming
CF 2041H - Sheet Music

Alice wants to count all sequences of notes of length n using pitches from 1 to k, but sequences that "move" the same way are considered identical.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2041D - Drunken Maze

We have a rectangular maze represented as a grid of characters. Empty cells are walkable, walls block movement, and two special cells mark the start and target positions.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsshortest-paths
CF 2041F - Segmentation Folds

We are given a segment on the number line defined by two integers $ell$ and $r$, and Peter can fold this segment in two specific ways: from left to right (LTR) and from right to left (RTL).

codeforcescompetitive-programmingbrute-forcedfs-and-similarnumber-theory
CF 2041E - Beautiful Array

We are asked to construct an integer array such that its mean is exactly a and its median is exactly b. The input consists of two integers, a and b, which are the desired mean and median, respectively.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2041B - Bowling Frame

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbinary-searchbrute-forcemath
CF 2041A - The Bento Box Adventure

The problem presents a scenario where a person visits one restaurant each day from Monday to Thursday, choosing a different restaurant each day from a set of five possible restaurants. The input gives the sequence of four distinct restaurants visited, one per day.

codeforcescompetitive-programmingimplementationsortings
CF 2041C - Cube

We are given a cube of size $n times n times n$, where every cell contains a weight. The task is to pick exactly $n$ cells such that no two chosen cells share the same coordinate in any dimension.

codeforcescompetitive-programmingbitmasksdfs-and-similardp
Kvant Math Problem 571

The condition gives control only on a sparse subsequence of the sequence, namely the indices $1,4,9,\dots,n^2$, and the weights are harmonic in $k$.

kvantmathematicsolympiad
CF 2042F - Two Subarrays

We have two arrays, a and b. For any subarray [l, r], its value is not just the sum of the elements of a inside it. We also add bl and br, the values attached to the two endpoints.

codeforcescompetitive-programmingdata-structuresdpimplementationmatrices
CF 2042D - Recommendations

Each user in the system is described by a closed interval on the number line. If we think of track IDs as positions on a huge axis from 1 to 10^9, then user i likes exactly the integer points in the segment $[li, ri]$.

codeforcescompetitive-programmingdata-structuresimplementationsortingstwo-pointers
CF 2042E - Vertex Pairs

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardivide-and-conquergreedyimplementationtrees
CF 2042B - Game with Colored Marbles

We are asked to compute Alice's final score in a sequential marble-taking game. There is a collection of n marbles, each with a specific color. Alice and Bob alternate turns, starting with Alice. Each turn consists of removing one marble.

codeforcescompetitive-programminggamesgreedy
CF 2042C - Competitive Fishing

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programminggreedy
CF 2042A - Greedy Monocarp

We are given several independent test cases. In each one there is a collection of chests, each starting with some number of coins. We are allowed to increase the number of coins in any chests, with no limit on how many we add, but we are trying to minimize the total coins we add.

codeforcescompetitive-programminggreedysortings
CF 2043G - Problem with Queries

We are given an array of integers and need to handle two types of queries. The first type updates a single element in the array. The second type asks for the number of pairs of indices within a specified subarray that contain different values.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementation
CF 2043F - Nim

We are asked to consider multiple rounds of the game Nim played on contiguous subarrays of an array of integers. Each integer represents a pile of stones.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdpgamesgreedyimplementationshortest-paths
CF 2043E - Matrix Transformation

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdfs-and-similargraphsgreedyimplementation
CF 2043D - Problem about GCD

We are asked to find two numbers $A$ and $B$ inside a closed range $[l, r]$ such that their greatest common divisor is exactly $G$, and the distance $ The inputs $l$, $r$, and $G$ can be as large as $10^{18}$, which rules out any solution that iterates through the entire range…

codeforcescompetitive-programmingbrute-forceflowsmathnumber-theory
CF 2043A - Coin Transformation

We start with a single coin whose value is given by an integer $n$. The only allowed move takes a coin whose value is strictly greater than 3, and replaces it with exactly two coins, each having value equal to the floor of one quarter of the original value.

codeforcescompetitive-programmingbrute-forcemath
CF 2043B - Digits

The failure you show is not enough to diagnose the algorithm itself. Let's trace what happened: The input contains 5 test cases: The program produced only: instead of: This means the code successfully processed the first test case and then terminated before handling the…

codeforcescompetitive-programmingmathnumber-theory
CF 2043C - Sums on Segments

We are given an array where almost every element is either 1 or -1, with at most one element allowed to be any integer. Our task is to find all distinct sums of contiguous subarrays. The sum of a subarray is simply the sum of its elements.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpgreedymath
Kvant Math Problem 408

Let the original rectangles have side lengths $a$ and $b$, and let their ratio be $r = \frac{a}{b} > 0$.

kvantmathematicsolympiad
CF 2044H - Hard Demon Problem

We are given an $n times n$ matrix of positive integers and multiple queries, each specifying a rectangular submatrix.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpimplementationmath
CF 2044G2 - Medium Demon Problem (hard version)

The error in your Python solution is a simple syntax mistake: the map(int, input().split()) call for reading b is missing a closing parenthesis. This prevents the code from running at all. Once that is fixed, the solution logic itself can remain the same.

codeforcescompetitive-programmingdfs-and-similardpdsugraphsimplementationtrees
CF 2044G1 - Medium Demon Problem (easy version)

Each spider chooses exactly one recipient. We can view this as a directed graph where every vertex has out-degree exactly one. Initially every spider owns one plushie. During a year, every spider that currently has a plushie sends one plushie along its outgoing edge.

codeforcescompetitive-programmingdfs-and-similargraph-matchingsgraphsimplementationtrees
CF 2044D - Harder Problem

We are asked to construct an array b from a given array a such that for every prefix of b up to index i, the element a[i] is one of the modes of that prefix.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2044F - Easy Demon Problem

We are given two arrays, a and b. From them we build an implicit matrix $$M{i,j}=ai bj.$$ The beauty of the matrix is the sum of all its entries.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresmathnumber-theory
CF 2044E - Insane Problem

We are asked to count the number of pairs of integers $(x, y)$ that satisfy two interval constraints and a geometric relationship. Specifically, $x$ must lie in the interval $[l1, r1]$, $y$ must lie in $[l2, r2]$, and $y / x$ must be an integer power of $k$.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmathnumber-theory
CF 2044C - Hard Problem

We are asked to assign monkeys to seats in a classroom with exactly two rows of m seats each. The monkeys come in three categories: a monkeys that will only sit in the first row, b monkeys that will only sit in the second row, and c monkeys that have no preference.

codeforcescompetitive-programminggreedymath
CF 2044B - Normal Problem

We are given a string consisting only of the letters p, q, and w. Ship observes this string from outside a glass window, giving us string a. When Ship moves inside the store and looks through the same window, he sees string b. Our task is to determine what b looks like given a.

codeforcescompetitive-programmingimplementationstrings
CF 2044A - Easy Problem

We are asked to count ordered pairs of positive integers $(a, b)$ such that $a + b = n$, for multiple test cases. Each test case gives a single integer $n$, and we must output the total number of pairs $(a, b)$ that satisfy the equation.

codeforcescompetitive-programmingbrute-forcemath
CF 2045L - Buggy DFS

We are asked to study a variation of Depth First Search (DFS) called Buggy DFS (BDFS). In BDFS, a standard DFS is implemented using an explicit stack, but with a subtle behavior: for every node u popped from the stack, the algorithm increments a counter for every neighbor of u…

codeforcescompetitive-programmingconstructive-algorithms
CF 2045M - Mirror Maze

Think of the laser beam as moving along the grid lines between cells. Whenever the beam enters a cell through one side, the content of that cell determines which side it leaves from. An empty cell does not change direction.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 2045K - GCDDCG

We are given a deck of $N$ cards, each labeled with an integer value between $1$ and $N$. The game has $N$ rounds.

codeforcescompetitive-programming
CF 2045I - Microwavable Subsequence

Thank you, now the problem is clear. The previous formula: does not always produce the optimal next floor because it computes the largest integer k ≤ (floor+D)//floor, but the next step may allow a smaller multiple of floor that lets a larger final floor later.

codeforcescompetitive-programmingdata-structures
CF 2045J - Xorderable Array

We are given an array of values $A$, and another array $X$. The task is not to modify $A$ directly, but to ask a very specific question about pairs of values from $X$. For any ordered pair $(p, q)$, we are allowed to rearrange the array $A$.

codeforcescompetitive-programmingbitmasksdata-structures
Kvant Math Problem 1557

Let $O$ be the center of the given circle.

kvantmathematicsolympiad
CF 2045H - Missing Separators

We are given a single long string made by writing several unknown words one after another in alphabetical order and then removing all separators. The original structure is a dictionary: words are distinct and sorted lexicographically.

codeforcescompetitive-programmingdpsortingsstring-suffix-structuresstrings
CF 2045E - Narrower Passageway

We are given a grid with two rows and $N$ columns. Each cell contains a value representing the strength of a soldier stationed there. On any given day, each column independently either disappears in fog or remains visible, with probability $1/2$.

codeforcescompetitive-programmingcombinatoricsdata-structures
CF 2045F - Grid Game 3-angle

We are given a triangular grid of size $N$, where row $r$ has $r$ cells. Certain cells initially contain some stones. Two players, Anda and Kamu, alternate turns, starting with Anda.

codeforcescompetitive-programminggamesmath
CF 2045G - X Aura

We are given a grid of size $R times C$ where each cell has a height from 0 to 9. You can move only between adjacent cells (up, down, left, right).

codeforcescompetitive-programminggraphsmathshortest-paths
CF 2045D - Aquatic Dragon

We are asked to navigate a line of islands numbered from 1 to N, starting at island 1 and ending at island N, while carrying a dragon whose stamina powers two special moves: swimming and flying.

codeforcescompetitive-programming
CF 2045B - ICPC Square

We are given a hotel with $N$ floors and an unusual elevator. From floor $x$, the elevator allows a jump to any floor $y$ such that $y$ is a multiple of $x$ and the difference $y - x$ does not exceed $D$.

codeforcescompetitive-programmingmathnumber-theory
CF 2045C - Saraga

We are given two strings, one called $S$ and another called $T$. We want to build a new string by taking some prefix of $S$ and some suffix of $T$, then concatenating them. The resulting string is called an abbreviation.

codeforcescompetitive-programminggreedystrings
CF 2045A - Scrambled Scrabble

We are asked to construct the longest possible word from a given string of uppercase letters under a very specific notion of syllables and letters. The alphabet is split into vowels (A, E, I, O, U), consonants (all others except Y), and a special letter Y that can act as either.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2046F2 - Yandex Cuneiform (Hard Version)

We are given a string template consisting of the letters 'Y', 'D', 'X', and '?' of length divisible by three. Our task is to determine whether it is possible to replace every question mark with one of 'Y', 'D', or 'X' such that the resulting string can be built according to…

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementation
CF 2046F1 - Yandex Cuneiform (Easy Version)

The problem asks us to determine whether a given string composed solely of the letters 'Y', 'D', and 'X' can be constructed incrementally following the rules of Yandex cuneiform.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 2046E1 - Cheops and a Contest (Easy Version)

We are given a set of participants, each described by two thresholds and a special attribute. Every participant either solves a problem because the problem is easy enough for their general skill, or because the problem matches their specialization and is still within their…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2046E2 - Cheops and a Contest (Hard Version)

I can't reliably write a correct editorial and solution for Codeforces 2046E2 - Cheops and a Contest (Hard Version) from the statement alone. This is a 3500-rated constructive/greedy problem whose solution depends on a nontrivial characterization and construction.

codeforcescompetitive-programminggreedyimplementation
CF 2046D - For the Emperor!

We are given a directed graph where each vertex represents a city and each directed edge represents a road that allows messengers to travel one way. Some cities initially contain a number of messengers.

codeforcescompetitive-programmingflowsgraphs
CF 2046C - Adventurers

Each city is a point on the plane. We choose a dividing point $(x0,y0)$, which splits the plane into four regions: $$begin{aligned} &x ge x0, y ge y0 &x < x0, y ge y0 &x ge x0, y < y0 &x < x0, y < y0 end{aligned}$$ Every city belongs to exactly one of these regions, according…

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingsternary-searchtwo-pointers
Kvant Math Problem 1530

Numbers $1,2,\dots,2p$ split into residue classes modulo $p$ as

kvantmathematicsolympiad
CF 2046A - Swap Columns and Find a Path

We are given a two-row matrix with $n$ columns, where each cell contains an integer. We can swap any two columns any number of times. After performing swaps, we must choose a path from the top-left cell $(1,1)$ to the bottom-right cell $(2,n)$.

codeforcescompetitive-programminggreedysortings
CF 2046B - Move Back at a Cost

We are given a sequence of integers, and we are allowed to repeatedly perform a very specific transformation: pick any element, increase it by one, and move it to the end of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 2048I2 - Kevin and Puzzle (Hard Version)

We are asked to count arrays of non-negative integers that satisfy conditions imposed by a string of L and R characters.

codeforcescompetitive-programmingbitmasksfftmath
CF 2048G - Kevin and Matrices

There is not enough information to diagnose the algorithm from the sample alone. The input contains only pairs (n, k), and the expected outputs are permutations: Many different Codeforces and contest problems use exactly this input format and require constructing a permutation…

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmath
CF 2048I1 - Kevin and Puzzle (Easy Version)

We are asked to construct an array of non-negative integers corresponding to a string of directions, where each character in the string specifies a condition about the count of distinct numbers in either the prefix or suffix of the array.

codeforcescompetitive-programmingconstructive-algorithms
CF 2048H - Kevin and Strange Operation

We are given a binary string s composed of 0s and 1s. Kevin can repeatedly perform a special operation: choose a position p, replace every character before it with the maximum of itself and the next character, then remove the character at position p.

codeforcescompetitive-programmingdata-structuresdp
CF 2048E - Kevin and Bipartite Graph

We are asked to design a bipartite graph for a poster pattern. The left part has $2n$ vertices, and the right part has $m$ vertices, with every left vertex connected to every right vertex. Each edge must be colored with an integer between $1$ and $n$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 2048F - Kevin and Math Class

We are given two arrays of the same length. The first array represents the values we want to eventually reduce to ones, and the second array controls how fast we can reduce segments. A single operation chooses a contiguous segment.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpimplementationmathtrees
CF 2048B - Kevin and Permutation

The reported failure is not caused by the algorithm's logic. The traceback shows: at: This means that somewhere before the call, the name solve was overwritten with None: or equivalently: and then later: was executed.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2048D - Kevin and Competition Memories

We are given a fixed list of problem difficulties and a list of participant ratings. If a participant has rating $ai$, they solve exactly those problems whose difficulty is at most $ai$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedysortingstwo-pointers
Kvant Math Problem 1506

For a fixed interval $[a,b]$, the condition that the sums of integrals over white and black subintervals are equal for every polynomial in a given family can be rewritten as the vanishing of a signed…

kvantmathematicsolympiad
CF 2048C - Kevin and Binary Strings

We are given a binary string where the first character is always 1. From this string, we must pick two non-empty substrings, and we are allowed to pick the same substring twice or pick overlapping ones.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementationstrings
CF 2048A - Kevin and Combination Lock

We are given a starting integer and a small set of operations that modify it. The goal is to determine whether we can eventually reduce the number exactly to zero. The two operations behave very differently.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathnumber-theory
CF 2049F - MEX OR Mania

The task asks us to process a sequence of integers and repeatedly answer the following: after each update to an element, what is the length of the longest contiguous subarray for which the MEX minus the bitwise OR of all elements equals exactly one.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdsuimplementation
CF 2049E - Broken Queries

We are asked to determine a hidden integer $k$ in an interactive setting, where $k$ controls the behavior of a device that responds to range queries on a hidden binary array of length $n$. The array contains exactly one 1 and all other elements are 0.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceconstructive-algorithmsimplementationinteractive
CF 2049D - Shift + Esc

We are given a grid of integers with $n$ rows and $m$ columns. Each cell contains a non-negative integer. We start at the top-left corner and want to reach the bottom-right corner, moving only right or down.

codeforcescompetitive-programmingbrute-forcedp
CF 2049B - pspspsps

I can't reliably diagnose the algorithmic bug from the information provided. The sample input/output pair is not enough to reconstruct the original problem, and the fact that the program now produces a blank output instead of a traceback suggests that we're no longer looking…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraph-matchingsimplementation
CF 2049A - MEX Destruction

We are given several independent test cases. In each test case, there is an array of small integers. The allowed operation takes any contiguous segment of the array, computes the MEX of the values inside that segment, and replaces the entire segment with that single value.

codeforcescompetitive-programminggreedyimplementation
CF 2049C - MEX Cycle

We are given a circular arrangement of $n$ nodes, each representing a dragon. Every dragon is connected to its two neighbors in the circle, and additionally there is one extra undirected edge between two specified nodes $x$ and $y$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementation
CF 2050F - Maximum modulo equality

Thank you for the clarification. I see exactly why the previous solution fails. The core issue is that the greedy left-to-right redistribution is too strict: it assumes you can only push surplus to the next element, but in reality the allowed operations let you shift values…

codeforcescompetitive-programmingdata-structuresdivide-and-conquermathnumber-theory
CF 2050D - Digital string maximization

We are given a string of digits, representing a number without leading zeros. We can repeatedly perform a restricted operation: pick any digit except the leftmost one or zero, decrease it by one, and swap it with the digit immediately to its left.

codeforcescompetitive-programmingbrute-forcegreedymathstrings
CF 2050G - Tree Destruction

We are given a tree, which is an acyclic connected graph, with $n$ vertices. The task is to select two vertices, $a$ and $b$, and remove all vertices along the unique path between them, including $a$ and $b$ themselves.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 2050E - Three Strings

We are given three strings: a, b, and c. Conceptually, c is formed by taking letters from a and b in some interleaving order. At each step, one letter is taken from the front of either a or b and appended to c.

codeforcescompetitive-programmingdpimplementationstrings
Kvant Math Problem 1479

The problem asks for the maximum number $K(n)$ of quadruples of natural numbers summing to $n$, under the global constraint that all numbers appearing in all quadruples are pairwise distinct.

kvantmathematicsolympiad
CF 2050B - Transfusion

We are given an array of integers representing “pools” of some resource. At each operation, we can pick an element that is not at the boundaries and move one unit from one neighbor to the other neighbor.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 2050A - Line Breaks

We are given a list of words and a fixed-length strip that can hold a certain number of characters. The task is to decide how many words we can consecutively place on this first strip without exceeding its length, while the remaining words go on a second strip that has…

codeforcescompetitive-programmingimplementation
CF 2050C - Uninteresting Number

We are given a very long decimal string, and we are allowed to repeatedly modify it digit by digit. A move picks one digit, replaces it with the value of its square, and keeps it as a single decimal digit only if the square is still between 0 and 9.

codeforcescompetitive-programmingbrute-forcedpmath
CF 2051G - Snakes

We are asked to place a set of snakes on a very long 1-dimensional strip of cells. Each snake initially occupies a single cell, and over a sequence of events it can either grow to the right or shrink from the left.

codeforcescompetitive-programmingbitmasksdpdsugraphs
CF 2051E - Best Price

The algorithm itself is correct. The symptom is that the program produces no output at all, not incorrect output. That means the bug is not in the logic for determining pass/fail. It is in the program structure.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedysortings