brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2025A - Two Screens

We are given two screens that can each display sequences of uppercase letters. Initially both screens are empty. At each second, we can either append a single letter to one of the screens, or copy the entire sequence from one screen to the other, replacing what was on the…

codeforcescompetitive-programmingbinary-searchgreedystringstwo-pointers
Kvant Math Problem 422

Let $\triangle ABC$ be arbitrary.

kvantmathematicsolympiad
CF 2026F - Bermart Ice Cream

We are managing a growing family of stores, where each store contains a multiset of ice cream types. Each type has two attributes: a cost and a tastiness value. Stores are not independent.

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquerdpimplementationtrees
CF 2026D - Sums of Segments

We are given an integer array a of length n. From a, we can generate a much larger array b that contains all possible contiguous subarray sums of a, listed in a specific order: first all sums starting at index 1, then all sums starting at index 2, and so on.

codeforcescompetitive-programmingbinary-searchdata-structuresdpimplementationmath
CF 2026E - Best Subsequence

We are given several independent test cases. In each test case we start with an array of integers, and we are allowed to choose any subsequence of it, meaning we may delete elements but cannot reorder what remains.

codeforcescompetitive-programmingbitmasksdfs-and-similarflowsgraph-matchingsgraphs
CF 2026C - Action Figures

We are given a sequence of action figures numbered from 1 to n. Figure i costs i coins, but it cannot be bought immediately on day 1; it only becomes available starting from day i. After day n, everything is available.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresgreedyimplementation
CF 2026A - Perpendicular Segments

The problem asks us to construct two line segments on a 2D integer grid. We are given a rectangular area defined by $X$ and $Y$ and a minimum length $K$. Each segment must have integer endpoints within the rectangle, and both must have lengths at least $K$.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedymath
CF 2026B - Black Cells

We are given a one-dimensional strip of cells numbered from 0 up to $10^{18}$. Initially all cells are white. We are required to paint certain cells black, and we are allowed to choose pairs of white cells whose distance is at most $k$ to paint them black simultaneously.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedy
CF 2027E2 - Bit Game (Hard Version)

We are asked to analyze a multi-pile turn-based game between Alice and Bob. Each pile has a fixed maximum move size, denoted $ai$, and a maximum number of stones, $bi$.

codeforcescompetitive-programmingbitmasksdpmath
CF 2027E1 - Bit Game (Easy Version)

Each test case gives us several independent piles of stones. Every pile behaves like a small game on its own: on your turn you pick a pile and remove some positive number of stones from it, but the move is heavily constrained.

codeforcescompetitive-programmingbitmasksbrute-forcegamesmath
Kvant Math Problem 394

Let

kvantmathematicsolympiad
CF 2027A - Rectangle Arrangement

We are given several axis-aligned rectangles, each with fixed integer width and height. Every rectangle must be placed somewhere on an infinite grid, and when placed it paints exactly the cells inside that rectangle black.

codeforcescompetitive-programminggeometryimplementationmath
CF 2028F - Alice's Adventures in Addition

We are given a sequence of integers and we are allowed to insert either addition or multiplication operators between consecutive elements. Multiplication has higher precedence than addition, so the expression is evaluated as a sum of several multiplicative blocks.

codeforcescompetitive-programmingbitmasksbrute-forcedpimplementation
CF 2028B - Alice's Adventures in Permuting

We are asked to determine how many operations it takes to turn a linearly generated array into a permutation of integers from 0 to n−1. The array is defined by three numbers n, b, and c, and follows the formula ai = b (i - 1) + c for 1 ≤ i ≤ n.

codeforcescompetitive-programmingbinary-searchimplementationmath
CF 2028E - Alice's Adventures in the Rabbit Hole

We are given a tree with n vertices where vertex 1 is considered the exit of the rabbit hole, and Alice starts at some vertex v. Each turn a fair coin is flipped. On heads, Alice chooses an adjacent vertex to move to.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgamesgreedymathprobabilitiestrees
CF 2028D - Alice's Adventures in Cards

The problem can be viewed as a graph traversal on a set of n card types. Alice starts with card 1 and wants to acquire card n by trading with three other players: Queen, King, and Jack.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgraphsgreedyimplementationternary-search
CF 2028A - Alice's Adventures in ''Chess''

Alice starts at the origin on a two-dimensional grid and can move in the four cardinal directions. She has a fixed sequence of moves that she repeats indefinitely.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 2028C - Alice's Adventures in Cutting Cake

We are given a long sheet cake divided into n sections, each with a tastiness value. Alice is at a party with m creatures, and she wants to cut the cake into m + 1 contiguous pieces. Each creature will only be happy if its piece has tastiness at least v.

codeforcescompetitive-programmingbinary-searchdpgreedytwo-pointers
CF 2029I - Variance Challenge

We are given an integer array and a fixed value $k$. We are allowed to perform an operation that selects a contiguous segment and adds $k$ to every element inside it.

codeforcescompetitive-programmingflowsgraphsgreedy
CF 2029H - Message Spread

We are given a small undirected graph where each edge has a probability of appearing on any given day. Initially, only vertex 1 knows a message.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdp
CF 2029G - Balanced Problem

We are asked to maximize a weighted sum over an array of integers that starts as all zeros. The array has length $n$ and receives $m$ initial operations, each of which increases a prefix or suffix of the array by 1.

codeforcescompetitive-programmingdata-structuresdp
CF 2029E - Common Generator

We are asked to find a number $x ge 2$ such that every number in a given array $a$ can be generated from $x$ using a special additive rule. The rule allows us to repeatedly add to $x$ one of its divisors that is at least 2, until we reach the target number.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathnumber-theory
CF 2029F - Palindrome Everywhere

We are given a cycle graph with $n$ vertices labeled $0$ to $n-1$. Each edge in the cycle has a color, either red or blue.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedy
CF 2029C - New Rating

Ah, now I see the subtle mistake. The previous logic assumed that putting the maximum first and subtracting each element from the maximum works, but that is not correct for the actual score definition: the score is $$sum{i=1}^n (ci - bi)$$ where $ci$ is the prefix maximum up…

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedy
CF 2029D - Cool Graph

We are given a simple undirected graph with $n$ vertices and $m$ edges. The graph can be arbitrary but contains no self-loops or multiple edges. We are allowed to perform a "triangle flip" operation on any three distinct vertices $a$, $b$, $c$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardsugraphsgreedytrees
CF 2029B - Replacement

We are given a binary string s of length n and another binary string r of length n-1. The problem describes a game where we repeatedly shorten s by replacing any adjacent pair of differing bits with the next character in r. On each turn, we must pick an index k such that s[k] !

codeforcescompetitive-programmingconstructive-algorithmsgamesstrings
CF 2029A - Set

We are asked to consider a contiguous set of integers $S$ from $l$ to $r$ and repeatedly remove numbers from $S$ according to a simple rule. A number $x$ can only be removed if there are at least $k$ multiples of $x$ in $S$, counting $x$ itself.

codeforcescompetitive-programminggreedymath
CF 2030G1 - The Destruction of the Universe (Easy Version)

We are asked to consider a universe of planets, each defined by an interval of vulnerability [li, ri]. A set of planets can be destroyed simultaneously if their intervals overlap at at least one point.

codeforcescompetitive-programmingcombinatoricsgreedymath
CF 2030G2 - The Destruction of the Universe (Hard Version)

I can write the editorial, but I cannot reliably produce a correct solution/editorial from the problem statement alone for a 3100-rated combinatorics problem without reconstructing the full proof and implementation details.

codeforcescompetitive-programmingcombinatoricsmath
CF 2030D - QED's Favorite Permutation

The problem gives us a permutation of numbers from $1$ to $n$ and a string of directions, L and R, associated with each position in the permutation.

codeforcescompetitive-programmingdata-structuresimplementationsortings
CF 2030F - Orangutan Approved Subarrays

We are given an array, and each query asks whether a contiguous segment of it can be completely deleted using a very specific rule. The rule works with a set of “available values” initially containing every distinct number in the segment.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedyimplementationtwo-pointers
CF 2030E - MEXimize the Score

We are given an array and we look at all of its non-empty subsequences. For each chosen subsequence, we are allowed to split its elements into any number of groups, where each group is a multiset.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpgreedyimplementationmath
CF 2030A - A Gift From Orangutan

We are given an array and we are allowed to reorder it before processing. Once fixed, we scan it from left to right and maintain two running values: the smallest element seen so far and the largest element seen so far.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 2030C - A TRUE Battle

We are given a binary string where each character is a fixed boolean value. The players do not change these values. Their only action is deciding where to place binary operators between adjacent positions, specifically choosing either AND or OR for each gap.

codeforcescompetitive-programmingbrute-forcegamesgreedy
Kvant Math Problem 2875

Working

kvantmathematicsolympiad
CF 2031F - Penchick and Even Medians

The original problem is interactive: there is a hidden permutation, and we must locate the positions of the two middle values, namely $frac n2$ and $frac n2 + 1$, using median queries. For the hack version used in the archive, the interaction is removed.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractiveprobabilities
CF 2031E - Penchick and Chloe's Trees

The problem gives us a rooted tree constructed by Penchick with n vertices and asks us to determine the minimum depth d of a perfect binary tree that Chloe can construct, so that after performing a sequence of "node removal and child promotion" operations, Chloe’s tree…

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgreedyimplementationmathsortingstrees
CF 2031D - Penchick and Desert Rabbit

We are given a line of trees, each with a height. A rabbit starts at some position and can move between trees using a very specific rule that depends on both position and height. From a tree at index i, the rabbit can jump in two directions.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardpdsugreedyimplementationtwo-pointers
CF 2031B - Penchick and Satay Sticks

We have a permutation of the numbers $1$ through $n$. The target is the sorted permutation $[1,2,dots,n]$. The only allowed operation swaps two neighboring positions when the values differ by exactly $1$. For example, $3$ and $4$ may be swapped, but $3$ and $5$ may not.

codeforcescompetitive-programmingbrute-forcegreedysortings
CF 2031C - Penchick and BBQ Buns

We are asked to assign a value to each position in an array of length $n$. These values represent “fillings” placed on buns arranged in a line. The same filling may appear multiple times, but only under two strict rules.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 2031A - Penchick and Modern Monument

The problem presents a monument made of $n$ pillars, each with a height $hi$, where the heights are initially in non-increasing order. Penchick wants to modify the monument so that the pillar heights are in non-decreasing order.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedymath
CF 2032F - Peanuts

We are given a sequence of pockets, each containing a positive number of peanuts. Alice can partition the sequence into contiguous boxes of pockets.

codeforcescompetitive-programmingcombinatoricsdpgamesmath
CF 2032E - Balanced

We are given a circular array of odd length $n$, where each element is an integer. We can perform an operation on any index $i$ which increases the element at $i$ by 2 and its immediate neighbors by 1. The goal is to transform the array so that all elements are equal.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationmath
CF 2032D - Genokraken

We are tasked with reconstructing the parent array of a tree rooted at node 0, under a very specific structure. Each node is numbered from 0 to n-1, and for each node i ≥ 1, we want to find its parent node pi. The twist is that we do not see the tree directly.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgraphsgreedyimplementationinteractivetreestwo-pointers
CF 2032C - Trinity

We are given an array of integers representing potential triangle sides, and the allowed operation is to copy one element over another. The ultimate goal is to make every distinct triplet of elements form a non-degenerate triangle.

codeforcescompetitive-programmingbinary-searchmathsortingstwo-pointers
CF 2032A - Circuit

The problem describes a circuit with $n$ lights and $2n$ switches. Each light is connected to exactly two switches, and each switch is connected to exactly one light.

codeforcescompetitive-programminggreedyimplementationmathnumber-theory
CF 2032B - Medians

We start with an array that is simply the numbers from 1 to n in increasing order, where n is guaranteed to be odd. We are allowed to cut this array into several contiguous pieces. Every piece must also have odd length, and the number of pieces itself must be odd.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 2033G - Sakurako and Chefir

We are asked to analyze movement on a rooted tree. The tree has $n$ vertices, with vertex $1$ as the root. Chefir, starting at a given vertex $vi$, has a limited stamina $ki$.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgreedytrees
CF 2033F - Kosuke's Sloth

For a fixed integer $k$, look at the Fibonacci sequence and mark every position whose Fibonacci value is divisible by $k$. For example, when $k=2$: $$1,1,mathbf{2},3,5,mathbf{8},13,21,mathbf{34},dots$$ The marked positions are $3,6,9,dots$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 2033E - Sakurako, Kosuke, and the Permutation

We are given a permutation of numbers from 1 to n. We are allowed to repeatedly swap any two positions. After performing some swaps, we want the permutation to satisfy a structural condition on every index i.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similardsugraphsgreedymath
CF 2033D - Kousuke's Assignment

We are given an array of integers and need to identify subarrays, or contiguous segments, whose sum is zero. These segments are called beautiful. The task is not just to find all beautiful segments but to maximize the number of them without overlaps.

codeforcescompetitive-programmingdata-structuresdpdsugreedymath
CF 2033C - Sakurako's Field Trip

We are given a line of students, each associated with a topic of interest, represented by an integer. The disturbance of the line is counted as the number of adjacent pairs of students who share the same topic.

codeforcescompetitive-programmingdpgreedytwo-pointers
CF 2033A - Sakurako and Kosuke

We are asked to determine the winner of a turn-based game where two players move a dot along a number line starting at position zero. Sakurako always moves left by increasing odd numbers of units on her turn: -1, -5, -9, and so on.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
Kvant Math Problem 2864

The arrangement of the lines is a simple arrangement: every pair of lines intersects and no three are concurrent.

kvantmathematicsolympiad
CF 2033B - Sakurako and Water

We are given an $n times n$ grid of integers, where each cell represents a height. Negative values represent “bad” cells that we want to eliminate by increasing values.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 2034H - Rayan vs. Rayaneh

We are given a set of distinct positive integers. We want the largest subset with the property that no chosen number can be expressed as an integer linear combination of the remaining chosen numbers. For integers, the subgroup generated by a collection of numbers is very simple.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpnumber-theory
CF 2034G2 - Simurgh's Watch (Hard Version)

We are given a set of warriors, each assigned a watch interval defined by integer start and end times. At every integer moment covered by at least one warrior, we must ensure that among the warriors present, there is at least one color that occurs exactly once.

codeforcescompetitive-programminggreedyimplementation
CF 2034F1 - Khayyam's Royal Decree (Easy Version)

We are simulating a random process where a bag is filled by repeatedly drawing items from a multiset containing two types of objects: red items worth 2 units and blue items worth 1 unit.

codeforcescompetitive-programmingcombinatoricsdpmathsortings
CF 2034G1 - Simurgh's Watch (Easy Version)

We are given a set of closed intervals on the real line. Each interval represents the active time of one warrior. We must assign a color to every interval. At every real time moment covered by at least one interval, we look at all intervals containing that moment.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 2034F2 - Khayyam's Royal Decree (Hard Version)

We are asked to compute the expected total value of a collection of gems after a stochastic process with multiplicative bonuses. Khayyam starts with a chest containing n red rubies, each worth 2, and m blue sapphires, each worth 1.

codeforcescompetitive-programmingcombinatoricsdpmathsortings
CF 2034E - Permutations Harmony

We need to construct $k$ distinct permutations of length $n$ such that if we look at any position $i$, the sum of the values appearing at that position across all $k$ permutations is the same for every position.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedyhashingmath
CF 2034C - Trapped in the Witch's Labyrinth

We are given a grid where each cell either forces movement in one of four directions or is still undecided. Starting from any cell, a token follows arrows step by step, leaving the grid immediately if it goes outside.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsimplementation
CF 2034D - Darius' Wisdom

We are given a sequence of stone columns, each with a base and a small number of inscriptions on top: either 0, 1, or 2. We can think of the sequence as an array of integers a[i] representing the number of inscriptions on the i-th column.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 2034B - Rakhsh's Revival

The problem models Rakhsh's body as a line of $n$ spots, where each spot is either weak ($0$) or strong ($1$). Rostam wants to ensure that in any consecutive interval of $m$ spots, at least one spot is strong.

codeforcescompetitive-programmingdata-structuresgreedyimplementationtwo-pointers
CF 2034A - King Keykhosrow's Mystery

The problem asks us to find a number that satisfies two properties relative to two given numbers, $a$ and $b$. Specifically, we want the smallest integer $m$ such that $m$ is at least as large as one of the two numbers and the remainder of $m$ when divided by $a$ equals the…

codeforcescompetitive-programmingbrute-forcechinese-remainder-theoremmathnumber-theory
CF 2035H - Peak Productivity Forces

We are given two permutations of the same size and a very unusual operation that modifies the array in two independent segments split at a chosen index.

codeforcescompetitive-programmingconstructive-algorithms
CF 2035G2 - Go Learn! (Hard Version)

We are given an array of length $n$, but its values are not fixed. Instead, we must construct it. Alongside this, we are given $m$ constraints.

codeforcescompetitive-programmingdivide-and-conquerdp
Kvant Math Problem 2846

The word “ПЕТЯ” has five letters.

kvantmathematicsolympiad
CF 2035G1 - Go Learn! (Easy Version)

I can't provide a correct editorial and implementation for this problem from first principles without deriving and verifying the full dynamic programming recurrence.

codeforcescompetitive-programmingdptrees
CF 2035F - Tree Operations

We are given a rooted tree with n nodes, each carrying an initial nonnegative value. The task is to reduce all node values to zero using operations that are applied in a fixed cyclic order on the nodes: the first n operations are applied to nodes 1 through n sequentially, and…

codeforcescompetitive-programmingbinary-searchbrute-forcedfs-and-similardptrees
CF 2035E - Monster

We are fighting a monster with z health points using a weapon whose damage starts at zero. We can perform two operations: increase the weapon’s damage by one at a cost of x coins, or attack the monster for d damage at a cost of y coins.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedyimplementationmathternary-search
CF 2035D - Yet Another Real Number Problem

We are given an array of integers and allowed to perform operations that move powers of two from one element to a later element in the array. Specifically, if an element is even, we can divide it by two and multiply a later element by two.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquergreedyimplementationmath
CF 2035C - Alya and Permutation

We are asked to construct a permutation of numbers from 1 to $n$ in a way that maximizes a value $k$ after a sequence of bitwise operations.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 2035A - Sliding

We are given a rectangular grid with $n$ rows and $m$ columns. Every cell contains one person, and these people are numbered from 1 to $nm$ in row-major order, meaning numbering proceeds left to right within a row and then continues to the next row.

codeforcescompetitive-programmingimplementationmath
CF 2035B - Everyone Loves Tres

We are asked to construct the smallest decimal number of length $n$ that consists only of digits $3$ and $6$, such that it is divisible by both $33$ and $66$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 2141F - Array Reduction

Working

codeforcescompetitive-programming*specialgreedy
CF 2141E - Perfect Cut

The symptom here is actually very clear from the input/output pair: You are giving permutations, and the expected outputs are: But a correct inversion-counting or monotonic-feasibility solution would never produce those values.

codeforcescompetitive-programming*specialdpgreedy
CF 2141G - Good Robot Paths

We are given a set of black points on a Cartesian plane, each with integer coordinates. A robot can move up, down, left, or right by one unit per command.

codeforcescompetitive-programming*specialdata-structuresgeometrysortings
CF 2141B - Games

Two players each maintain a fixed sorted list of games they enjoy. They do not immediately know which common game to pick, so they go through a deterministic alternating process of suggesting games they personally like, one at a time, without repeating any suggestion.

codeforcescompetitive-programming*specialgreedy
CF 2141D - Avoid Minimums

Our systems have detected unusual activity coming from your system. Please try again later.

codeforcescompetitive-programming*specialgreedymath
Kvant Math Problem 2802

Let

kvantmathematicsolympiad
CF 2128F - Strict Triangle

We are given an undirected, connected graph with $n$ nodes and $m$ edges, where each edge has a weight that is not fixed but lies in a given interval $[li, ri]$.

codeforcescompetitive-programminggraphsgreedyshortest-paths
CF 2128E2 - Submedians (Hard Version)

We are asked to identify submedians in an array. More concretely, for each integer in the array range $1$ to $n$, we want to determine whether there exists a contiguous subarray of length at least $k$ such that the integer is a median of that subarray.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresmathtwo-pointers
CF 2128D - Sum of LDS

The failure you’re seeing is not an algorithmic issue at all. It’s a complete breakdown of input handling consistency across the solution.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgreedymath
CF 2128B - Deque Process

We are given a permutation of numbers, and we build a new sequence by repeatedly removing either the leftmost or rightmost remaining element. This produces a sequence of length n, but we are free to decide at each step whether to take from the left or the right.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingstwo-pointers
CF 2128E1 - Submedians (Easy Version)

We are given an array and a length constraint $k$. From this array, we want to select a contiguous segment of length at least $k$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedymath
CF 2127G2 - Inter Active (Hard Version)

We are dealing with a hidden structure, a permutation of size $n$, where every position points to exactly one value and no value repeats. There is an additional restriction that no element stays in its original position, so the permutation contains no fixed points.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsgraphsimplementationinteractivemathprobabilities
CF 2127F - Hamed and AghaBalaSar

You’re not dealing with a “small bug anymore” - the issue is that the last solution implicitly solved a different problem (monotone feasibility) than the one your samples are testing. We can prove that directly from the third failing case.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathprobabilities
CF 2127G1 - Inter Active (Easy Version)

We are given a hidden permutation of size $n$, with the additional promise that no element stays in its own position. So every index points to a different value, and every value appears exactly once. We cannot see this permutation directly.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractiveprobabilities
CF 2127E - Ancient Tree

We are given a rooted tree with weighted vertices, where each vertex either has a fixed color between 1 and k or a missing color represented by 0. The goal is to assign colors to all uncolored vertices to minimize the total weight of "cutie" vertices.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdfs-and-similardsugreedytrees
CF 2127D - Root was Built by Love, Broken by Destiny

We are given a connected undirected graph of n houses and m bridges. Each bridge must connect one house on the northern side of a river to one house on the southern side.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphstrees
CF 2127A - Mix Mex Max

At this point the failures are not coming from “a small bug in transitions” or “a corner case in logic”. They come from a much simpler fact: The code you are running is not implementing the problem you are testing. We can prove this directly from your sample.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
Kvant Math Problem 1594

The functional equation is

kvantmathematicsolympiad
CF 2127C - Trip Shopping

We are given two arrays of integers, a and b, representing prices of items in two categories. The game consists of k rounds. In each round, Ali selects two indices, and Bahamin can rearrange the four numbers at those indices arbitrarily, even swapping elements between arrays.

codeforcescompetitive-programminggamesgreedysortings
CF 2127B - Hamiiid, Haaamid... Hamid?

We are given a one-dimensional grid of length n, with some cells containing walls and others empty. Hamid is standing on one empty cell, and every day two things happen: first Mani places a wall on an empty cell not currently occupied by Hamid, then Hamid chooses a direction…

codeforcescompetitive-programminggamesgreedy
CF 2117H - Incessant Rain

We are given an array of integers and a sequence of queries. Each query updates a single element of the array, and after the update, we are asked for the maximum integer $k$ such that some subarray contains a $k$-majority.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortings
CF 2117F - Wildflower

We are given a rooted tree where vertex 1 is the root, and every node must be assigned a value either 1 or 2. Once these values are fixed, every node computes a quantity defined as the sum of values in its rooted subtree, meaning the node itself plus all of its descendants.

codeforcescompetitive-programmingcombinatoricsdfs-and-similartrees
CF 2117E - Lost Soul

The repeated runtime errors you are seeing are all caused by misaligned assumptions about the input format. Let me go step by step. Looking at your input: The first line 5 is the number of test cases.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2117G - Omg Graph

We are working with a weighted undirected connected graph where we need to travel from node 1 to node n. Every path is allowed to revisit vertices and edges, so cycles are permitted.

codeforcescompetitive-programmingbrute-forcedsugraphsgreedyshortest-pathssortings
CF 2117C - Cool Partition

We are given an array of integers and need to divide it into contiguous segments. Each element must appear in exactly one segment. A partition is considered cool if every element in a segment also appears in the next segment, if there is one.

codeforcescompetitive-programmingdata-structuresgreedy