brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2138D - Antiamuny and Slider Movement

We are given a sorted line of unit-sized sliders placed on integer positions along a very long track. Each slider keeps a fixed identity, and the initial configuration is strictly increasing, meaning no two sliders start at the same position.

codeforcescompetitive-programmingbrute-forcecombinatoricsimplementationmathsortings
CF 2138C2 - Maple and Tree Beauty (Hard Version)

We are given a rooted tree with n vertices. Each vertex must be labeled either 0 or 1, with exactly k zeros and n - k ones. The "name" of a vertex is the string formed by concatenating the labels along the path from the root to that vertex.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpffttrees
CF 2138B - Antiamuny Wants to Learn Swap

We are given a permutation of integers from 1 to $n$, and we must answer multiple queries about whether certain subarrays are "perfect" according to a special sorting rule.

codeforcescompetitive-programmingdata-structuresgreedytwo-pointers
CF 2138A - Cake Assignment

We have two people, Chocola and Vanilla, who start with exactly the same number of cakes, which is $2^k$ each. The total number of cakes is $2^{k+1}$. The goal is to redistribute the cakes so that Chocola ends up with exactly $x$ cakes and Vanilla gets the rest.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 2138C1 - Maple and Tree Beauty (Easy Version)

We are given a rooted tree with n vertices, where the root is vertex 1. Each vertex is labeled either 0 or 1, but we do not know the exact labeling. All we know is that exactly k vertices have label 0, and the remaining n - k have label 1.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphstrees
CF 2139A - Maple and Multiplication

We are asked to make two positive integers equal using a series of multiplication operations. Maple can choose either number and multiply it by any positive integer of her choice. The goal is to do this in the minimum number of operations.

codeforcescompetitive-programminggreedymath
CF 2140F - Sum Minimisation

We are given an array of integers and a special operation that can decrease some of its elements. For any chosen set of $k$ distinct indices, we sum the selected elements, take the remainder of this sum modulo $k$, and then decrease the smallest $y$ elements by 1, where $y$ is…

codeforcescompetitive-programmingnumber-theory
CF 2140E2 - Prime Gaming (Hard Version)

We have a sequence of n piles. The number of stones in each pile can be any integer from 1 to m. The game itself does not depend on the stone values while moves are being made. Players only choose positions to delete.

codeforcescompetitive-programmingbitmaskscombinatoricsdpprobabilities
CF 2140E1 - Prime Gaming (Easy Version)

We have a row of n piles. Each pile contains either 1 or 2 stones because this is the easy version and m ≤ 2. The game does not modify pile values. Players only remove piles.

codeforcescompetitive-programmingbitmaskscombinatoricsdp
CF 2140D - A Cruel Segment's Thesis

We are given several intervals on a number line. Each interval represents a “resource” with a left and right boundary. Initially none of these intervals are used. We repeatedly pick two unused intervals, and from each chosen interval we pick one point inside it.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 2140C - Ultimate Value

We are given a game played on an array of integers where two players take turns performing a single action: either end the game immediately or swap two elements at positions $l$ and $r$, which adds $r-l$ to a running cost.

codeforcescompetitive-programmingdata-structuresgamesgreedy
CF 2140B - Another Divisibility Problem

We are given a number $x$, and we must construct another positive integer $y$ such that a specific divisibility condition holds. The construction depends on forming a new number by concatenating the decimal representation of $x$ followed immediately by $y$.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 2140A - Shift Sort

We are given a binary string, which is a sequence of 0s and 1s, and the goal is to sort it into non-decreasing order using a specific operation.

codeforcescompetitive-programminggreedysortings
CF 2141I - Color the Tree

We are working with a tree where every vertex starts uncolored. In one move, we pick any two vertices, possibly the same vertex twice, and we “recolor” every vertex on the unique path between them.

codeforcescompetitive-programming*special
CF 2141H - Merging Vertices in a Graph

We start with an undirected simple graph on $n$ vertices. The graph evolves through an operation that removes two existing vertices and replaces them with a new vertex whose neighborhood is exactly the intersection of the neighborhoods of the removed vertices.

codeforcescompetitive-programming*specialdfs-and-similardsugraphs
CF 2141C - Minimum on Subarrays

The problem asks us to simulate a special structure that supports adding and removing elements from both ends, along with a min operation that accumulates the minimum of all current elements into a running sum.

codeforcescompetitive-programming*specialbrute-force
CF 2141A - Furniture Store

We are given a list of sofa models, each positioned on a website in a fixed order. Every model has a price, and every customer scans the list from left to right, picking the first sofa whose price does not exceed their budget.

codeforcescompetitive-programming*specialimplementation
CF 2143F - Increasing Xor

We are given an array of small integers, and we are allowed to repeatedly pick two positions inside a chosen segment and XOR the value at the later index with the value at the earlier index.

codeforcescompetitive-programmingbitmasksdata-structuresmath
CF 2143D2 - Inversion Graph Coloring (Hard Version)

We are given a sequence of integers and asked to count how many of its subsequences can be colored in red and blue such that, for every inversion (a pair of indices $i < j$ with $ai aj$), the two elements have different colors.

codeforcescompetitive-programmingbinary-searchcombinatoricsdata-structuresdptwo-pointers
CF 2143E - Make Good

We start with a string made only of opening and closing brackets. The string is not fixed: we are allowed to repeatedly pick two adjacent identical brackets and flip them as a pair.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathstrings
CF 2143D1 - Inversion Graph Coloring (Easy Version)

We are given a sequence of integers, each between 1 and n, and we want to count subsequences that can be “colored” red or blue in such a way that every inversion in the subsequence has endpoints of different colors.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpgreedytwo-pointers
CF 2143A - All Lengths Subtraction

We are given a permutation of length $n$, which is an array containing all integers from 1 to $n$ in some order, with no duplicates. We must perform a series of exactly $n$ operations, one for each $k$ from 1 to $n$.

codeforcescompetitive-programmingbrute-forcetwo-pointers
CF 2143B - Discounts

We are asked to buy a set of products with individual prices while minimizing the total cost using discount vouchers. Each voucher allows you to pick a fixed number of products and get the cheapest among them for free.

codeforcescompetitive-programminggreedysortingstwo-pointers
CF 2143C - Max Tree

We are given a tree with n vertices and n-1 edges, each edge carrying two non-negative integers x and y. The problem asks us to assign distinct integers from 1 to n to the vertices so that the sum of edge contributions is maximized.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 2144E1 - Looking at Towers (easy version)

We are given an array of tower heights, and we consider subsequences formed by deleting some elements while preserving order. For any chosen subsequence, we “scan” it from the left and record every element that is strictly larger than all previously seen elements.

codeforcescompetitive-programmingcombinatoricsdp
CF 2144F - Bracket Groups

We are given several bracket strings, each of length at most $k$, and we must assign every string to exactly one group. For each group we also construct a single “reference” regular bracket sequence of length exactly $k$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpstring-suffix-structuresstrings
CF 2144E2 - Looking at Towers (difficult version)

We are given a sequence of tower heights and need to count subsequences that preserve the "visibility from left" and "visibility from right" sets.

codeforcescompetitive-programmingcombinatoricsdata-structuresdp
CF 2144D - Price Tags

We are running a clearance sale for a store with multiple items, each with a fixed original price. The store allows a uniform discount via division by an integer factor $x 1$, where the new price of an item is the ceiling of its original price divided by $x$.

codeforcescompetitive-programmingbrute-forcedpmath
CF 2144B - Maximum Cost Permutation

We are given an array p of length n where some positions contain integers from 1 to n and others are zeros. No positive integer appears more than once.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2144A - Cut the Array

We are given an array of non-negative integers and are asked to split it into three contiguous non-empty subarrays: a prefix, a middle part, and a suffix. For each subarray, we calculate the sum modulo 3.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathnumber-theory
CF 2144C - Non-Descending Arrays

We are given two integer arrays of the same length, a and b. At each index, we can either leave the elements as they are or swap a[i] with b[i]. After performing any subset of these swaps, both arrays must be non-descending for the subset to be considered "good.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2145E - Predicting Popularity

We are tasked with predicting how many users on a streaming platform will watch a movie, given each user's preference for action and drama, and the movie's action and drama levels. Each user has thresholds for action and drama.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 2145G - Cost of Coloring

We are given a rectangular sheet with $n$ rows and $m$ columns, initially uncolored. Our task is to determine how many ways we can color it “beautifully” with exactly $k$ colors, using the fewest operations possible for each number of operations from $min(n, m)$ to $n+m-1$.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpfftmath
CF 2145F - Long Journey

We are given a very long one-dimensional strip of cells, numbered from 0 up to m. A chip starts at cell 0 and wants to reach cell m in as few turns as possible. Each turn, the chip either stays where it is or moves one step to the right.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdpgraphsgreedymathmatricesnumber-theory
CF 2145D - Inversion Value of a Permutation

We are asked to construct a permutation of length $n$, meaning we must arrange the numbers from $1$ to $n$ exactly once in some order. For any fixed permutation, we can look at its inversions, which are pairs of positions where a larger number appears before a smaller one.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardp
CF 2145C - Monocarp's String

We are given a binary string consisting only of a and b. From this string, we are allowed to remove exactly one contiguous block of characters, possibly empty. After this deletion, we look at the remaining characters and count how many a and b are left.

codeforcescompetitive-programmingbinary-searchgreedystrings
CF 2145B - Deck of Cards

We are given a deck of cards numbered from 1 to n, initially sorted with 1 on top and n on the bottom. Monocarp performs a sequence of k operations that remove cards from either the top, the bottom, or ambiguously from either end.

codeforcescompetitive-programminggreedyimplementation
CF 2145A - Candies for Nephews

Monocarp wants to divide a certain number of candies evenly among his three nephews. He starts with n candies and needs to figure out how many more, if any, he must buy to make the total divisible by three.

codeforcescompetitive-programmingmath
CF 2146F - Bubble Sort

The task is to count permutations of length $n$ that satisfy a specific condition derived from bubble sort. For a permutation $p$, define $bi$ as the number of bubble sort rounds required to sort the prefix $[p1, dots, pi]$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdp
CF 2146E - Yet Another MEX Problem

We are given an array that grows one element at a time from left to right. After each new element is appended, we look at all subarrays that end exactly at this new position. Among those subarrays, we want the one that maximizes a particular score.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresdivide-and-conquergreedyhashing
CF 2146D2 - Max Sum OR (Hard Version)

We are given an integer interval $[l, r]$. From this interval we form a list containing every integer exactly once. One copy of this list is fixed as array $b$. The other copy, array $a$, is initially identical but we are allowed to permute it arbitrarily.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedy
CF 2146D1 - Max Sum OR (Easy Version)

We are given two integers, l and r, where l is always zero in this easy version and r is less than 200,000. From these, we define an array b that contains every integer from l to r, inclusive. We are allowed to permute a copy of this array, which we call a.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedytrees
CF 2146B - Merging the Sets

We are given several collections of integers, where each collection can be thought of as a “bundle of labels” from the range $1$ to $m$.

codeforcescompetitive-programminggreedyimplementation
CF 2146C - Wrong Binary Search

We are asked to construct a permutation of integers from 1 to n based on a binary string that marks which numbers are “stable” under a randomized variant of binary search.

codeforcescompetitive-programmingbinary-searchconstructive-algorithms
CF 2146A - Equal Occurrences

We are given a non-decreasing array of integers, and we want to find a subsequence whose elements all appear the same number of times. A subsequence can skip elements but cannot change their order.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 2147I2 - Longest Increasing Path (Hard Version)

We are asked to construct a long sequence of integers, where the sequence behaves like a walk on the number line. Each consecutive pair defines a jump distance, and these jump distances must strictly increase as we move along the sequence.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2147G - Modular Tetration

We are asked to analyze sequences generated by repeated exponentiation modulo a given number. Specifically, for a positive integer $a$, we define a sequence $bn$ by $b0 = 1$ and $bn = a^{b{n-1}}$ for $n ge 1$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 2147I1 - Longest Increasing Path (Easy Version)

We are asked to construct a sequence of integers of length $n$ placed on the number line. The only structural constraint is about consecutive jumps: if we define the jump sizes as $ So the sequence of distances is strictly increasing, while the actual points $ai$ can move left…

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2147H - Maxflow GCD Coloring

The graph defines a family of pairwise connectivity strengths. For every ordered pair of distinct vertices, we look at the maximum flow value between them when treating edges as undirected capacitated connections.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraphs
CF 2147F - Exchange Queries

We are given a set of items, and each item is ranked in two independent ways. One ranking comes from permutation p, the other from permutation s.

codeforcescompetitive-programmingcombinatoricsdata-structuresgreedy
CF 2147D - Game on Array

We are given a sequence of positive integers, representing a set of “tiles” with values. Two players, Alice and Bob, take turns picking a number that currently exists in the array.

codeforcescompetitive-programminggamesgreedy
CF 2147E - Maximum OR Popcount

We are given an array of non-negative integers, and for each query we are allowed to increment any elements of the array a certain number of times.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedata-structuresgreedy
CF 2147A - Shortest Increasing Path

We are on a two-dimensional grid starting at the origin $(0, 0)$ and want to reach a target $(x, y)$. Movement is constrained in two ways. First, we alternate axes: the first step moves right along $x$, the second up along $y$, the third along $x$ again, and so on.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2147C - Rabbits

We are given a row of flower pots, some with flowers and some empty. Each empty pot must host a rabbit, and we have to decide which way each rabbit will face: left or right. Rabbits are fidgety and may jump to the adjacent pot in the direction they face.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedyimplementation
CF 2147B - Multiple Construction

We are asked to construct a permutation-like array of length $2n$, but with repetition allowed: every number from $1$ to $n$ must appear exactly twice. The real constraint is not placement, but spacing.

codeforcescompetitive-programmingconstructive-algorithms
CF 2148F - Gravity Falls

We are given several arrays of integers, each of potentially different lengths. We can think of these arrays as rows in a grid that we are allowed to stack in any order, left-aligned.

codeforcescompetitive-programminggreedyimplementationsortings
CF 2148G - Farmer John's Last Wish

We are given an array of integers representing objects lying on the floor. Farmer John is concerned with the greatest common divisor (GCD) of prefixes of this array.

codeforcescompetitive-programmingbinary-searchdata-structuresmathnumber-theory
CF 2148E - Split

We are given an array of positive integers and a parameter $k$. For any chosen segment $[l, r]$, we imagine splitting the array into two parts: inside the segment and outside the segment. Every element inside the segment is forced into a distinguished multiset, call it bucket 1.

codeforcescompetitive-programmingbinary-searchdata-structurestwo-pointers
CF 2148D - Destruction of the Dandelion Fields

We are given a sequence of fields, each containing some number of dandelions. We are allowed to choose the order in which we visit these fields, and each field is visited exactly once.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 2148C - Pacer

We are simulating a very simple movement process along a line of time, where each minute Farmer John either stays on his current side of a gym or runs to the opposite side. Each time he chooses to run, he earns one point.

codeforcescompetitive-programminggreedymath
CF 2148B - Lasers

We are working on a grid-like plane from the origin to a target point, but instead of being blocked by walls, the plane contains infinitely thin obstacles.

codeforcescompetitive-programminggeometry
CF 2148A - Sublime Sequence

The problem gives us a number x and a length n and asks us to construct a sequence by alternating x and -x, starting with x. We are then asked to compute the sum of all elements in that sequence.

codeforcescompetitive-programmingbrute-forcehashingmath
CF 2149G - Buratsuta 3

We are given an array of integers and many independent range queries. For each query segment, we must identify all values whose frequency inside that segment is strictly greater than one third of the segment length.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquerprobabilities
CF 2149F - Nezuko in the Clearing

Nezuko starts at position 0 on a number line with a certain number of health points, and she wants to reach position d. In each turn, she can either rest to gain one health point or move forward by one.

codeforcescompetitive-programmingbinary-searchmathternary-search
CF 2149D - A and B

We are given a binary string made only of two symbols, a and b. We are allowed to swap adjacent characters, so any operation is essentially a single step of bubble-sorting two neighbors.

codeforcescompetitive-programmingstrings
CF 2149E - Hidden Knowledge of the Ancients

We are given a sequence of integers representing symbols on an ancient tablet. Each test case asks us to count the number of continuous segments (subarrays) of this sequence that satisfy two conditions: the segment contains exactly k distinct numbers, and its length is at…

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 2149A - Be Positive

We are given an array of length $n$ where each element is either $-1$, $0$, or $1$. We are allowed to increment any element by one any number of times. The goal is to make the product of all elements strictly positive while performing the fewest possible operations.

codeforcescompetitive-programmingmath
CF 2149B - Unconventional Pairs

We are given an even-length array of integers representing participants in a show. The task is to form pairs of participants such that each participant is in exactly one pair, and the difference between the two numbers in a pair is minimized in a global sense.

codeforcescompetitive-programminggreedysortings
CF 2149C - MEX rose

We are given an array of integers, each between 0 and n, and a target number k. We can replace any element with any integer from 0 to n in a single operation. Our goal is to make the MEX of the array equal to k using the minimum number of replacements.

codeforcescompetitive-programminggreedy
CF 2150G - Counting Is Fun: The Finale

We are asked to count how many binary strings of fixed length and fixed composition can be formed such that two conditions hold simultaneously: the string must dominate a given reference string in lexicographic order, and it must admit at least one split point where both…

codeforcescompetitive-programmingcombinatoricsimplementation
CF 2150F - Cycle Closing

We are given a connected simple undirected graph. The graph is already partially filled with edges, and our goal is to make it a complete graph, meaning every pair of distinct vertices must end up connected by an edge. We are not allowed to directly add edges.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementationshortest-pathstrees
CF 2150E2 - Hidden Single (Version 2)

We are given a hidden array of length $2n-1$ that contains each number from 1 to $n$ exactly twice, except for a single number which appears only once. Our goal is to determine which number appears only once. We do not need to know its position, only its identity.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractivemathprobabilities
CF 2150E1 - Hidden Single (Version 1)

We are given a hidden array of length 2n-1, containing integers from 1 to n such that every number appears exactly twice except for one number that appears only once. Our goal is to identify the number that occurs exactly once. We do not need its position, only its value.

codeforcescompetitive-programmingdivide-and-conquerinteractivemathprobabilitiessortings
CF 2150D - Attraction Theory

We start with n people placed on positions 1 through n on a line. The initial configuration is completely rigid: person i starts at position i.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2150B - Grid Counting

We are asked to count the number of ways to color cells black in an $n times n$ grid given a list $a$ of length $n$. The entry $ak$ specifies how many black cells must appear in row $k$.

codeforcescompetitive-programmingcombinatoricsimplementationmath
CF 2150C - Limited Edition Shop

We are asked to analyze a situation where two players, Alice and Bob, pick objects from a shop in turn. Each object has a value from our perspective, and each player has their own preference order.

codeforcescompetitive-programmingdata-structuresdp
CF 2150A - Incremental Path

We are given a line of $10^9$ cells, each either black or white. Initially, a certain set of cells are black, and all others are white.

codeforcescompetitive-programmingdata-structureshashingimplementation
CF 2152H1 - Victorious Coloring (Easy Version)

We are given a tree with n vertices, each edge has a positive weight. The task is to assign nonnegative integer weights to the vertices themselves so that when we compute the minimum cost of a “victorious coloring” (coloring vertices red or yellow with at least one red)…

codeforcescompetitive-programmingdfs-and-similardpgreedy
CF 2152H2 - Victorious Coloring (Hard Version)

We are given a tree with weighted edges, and we are asked to assign nonnegative weights to vertices so that a certain “victorious coloring” has a minimum cost at least some value l, while keeping the sum of vertex weights as small as possible.

codeforcescompetitive-programmingdata-structuresgreedyschedules
CF 2152F - Triple Attack

We are given a sorted sequence of attack timestamps. Each query gives a contiguous segment of this sequence, and inside that segment we are allowed to delete some elements. The goal is to keep as many timestamps as possible while avoiding a specific failure condition.

codeforcescompetitive-programmingdata-structuresgreedy
CF 2152G - Query Jungle

We are given a rooted tree with root fixed at vertex 1. Some vertices are marked as “active” (contain a monster), others are not.

codeforcescompetitive-programmingdata-structuresimplementationmathmatricestrees
CF 2152A - Increase or Smash

We are given an array of zeros of length $n$, and a target array of positive integers. We want to reach the target array with as few operations as possible. There are two operations available. The first, Increase, adds the same positive integer to every element of the array.

codeforcescompetitive-programminggreedyimplementation
CF 2152E - Monotone Subsequence

We are given a hidden permutation of length $n^2 + 1$ and we need to find a monotone subsequence of length exactly $n+1$. The subsequence can either be increasing or decreasing.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyinteractivemath
CF 2152D - Division Versus Addition

We are given an array where every element starts at least 2, and two players repeatedly modify it until every value becomes 1.

codeforcescompetitive-programminggamesgreedymath
CF 2152B - Catching the Krug

We are asked to compute the maximum number of turns the Krug can survive against Doran on a square grid. The grid has coordinates from 0 to n in both rows and columns. The Krug moves first, either staying in place or moving to a vertically or horizontally adjacent cell.

codeforcescompetitive-programminggames
CF 2152C - Triple Removal

We are given a binary array, meaning each element is either 0 or 1, and we need to repeatedly remove triples of identical elements. Each removal has a cost defined as the minimum distance between consecutive elements in the triple.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 2153F - Odd Queries on Odd Array

We are given an array a of length n that satisfies a special property called "cute," which prevents certain repeating patterns of four indices.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresimplementationtrees
CF 2153D - Not Alone

We are given a circular sequence of integers, and we are allowed to change each value by paying unit cost per increment or decrement.

codeforcescompetitive-programmingdpgreedy
CF 2153E - Zero Trailing Factorial

We are asked to work with trailing zeros of factorials in arbitrary bases. Specifically, for any integer $xge 1$ and base $kge 2$, $vk(x!)$ counts how many times $k$ divides $x!$. For prime bases, this is straightforward: sum the integer divisions of $x$ by powers of $p$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 2153C - Symmetrical Polygons

We are given several collections of stick lengths, and for each collection we want to pick some of these sticks to form the sides of a polygon. Each chosen stick becomes exactly one side, so we are not allowed to split or merge sticks.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedyimplementationsortings
CF 2153A - Circle of Apple Trees

We are given a circle of apple trees, each bearing a single apple with an associated beauty value. You start at tree one and walk around the circle repeatedly. At each tree, you have the choice to eat the apple or skip it.

codeforcescompetitive-programminggreedysortings
CF 2153B - Bitwise Reversion

We are asked to determine whether it is possible to construct three non-negative integers, $a$, $b$, and $c$, such that their pairwise bitwise ANDs equal three given integers $x$, $y$, and $z$. Specifically, the constraints are that $a & b = x$, $b & c = y$, and $a & c = z$.

codeforcescompetitive-programmingbitmasksgreedy
CF 2154F2 - Bombing (Hard Version)

We are asked to count the number of ways to fill in missing values in a partially specified permutation such that the resulting permutation can be split into two consecutive subsequences whose combined order gives the sorted permutation from $1$ to $n$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2154F1 - Bombing (Easy Version)

We are given an array of length $n$ that is supposed to be a permutation of $1 dots n$, but some positions are unknown and marked as $-1$.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsimplementationmath
CF 2154D - Catshock

The tree represents a world where a cat starts at node 1 and tries to reach node n. You cannot directly control the cat’s path when it moves.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstreestwo-pointers
CF 2154E - No Mind To Think

We are given an array of positive integers. We are allowed to choose one odd length $x$, and then repeatedly perform an operation up to $k$ times. Each operation picks any subsequence of length $x$, computes its median, and overwrites all chosen elements with that median value.

codeforcescompetitive-programmingbinary-searchdivide-and-conquergreedysortingsternary-searchtwo-pointers
CF 2154C2 - No Cost Too Great (Hard Version)

We are given an array of integers a, where each element behaves like a “value sitting on a position”, and a second array b which describes how expensive it is to increase each corresponding a[i] by 1.

codeforcescompetitive-programminggreedymathnumber-theory
CF 2154B - Make it Zigzag

We are given an array of integers and want to transform it into a zigzag sequence. A zigzag array is one where each element alternates between being smaller and larger than its neighbor: the first element is smaller than the second, the second is larger than the third, and so on.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2154A - Notelock

We are given a binary string consisting of 0s and 1s and a positive integer k. Each 1 in the string can be “turned off” by Teto according to a simple local rule: if a 1 is not protected and there are no other 1s in the previous k-1 positions, it can be changed to 0.

codeforcescompetitive-programminggreedytwo-pointers
CF 2154C1 - No Cost Too Great (Easy Version)

We are given an array of positive integers a of length n. For each element ai, we can increment it by 1 any number of times at a cost of 1 per increment.

codeforcescompetitive-programminggreedyimplementationmathnumber-theory