brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2171F - Rae Taylor and Trees (hard version)

We are asked to construct a tree on $n$ vertices labeled from $1$ to $n$ such that for every edge connecting vertices $u$ and $v$ with $u < v$, the vertex $u$ appears before $v$ in a given permutation $p$.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdpdsugreedyimplementationtrees
CF 2171E - Anisphia Wynn Palettia and Good Permutations

We are asked to construct permutations of integers from 1 to n such that in every consecutive triplet of elements, at most six indices are "bad." An index i is bad if the three consecutive numbers starting at i are pairwise coprime.

codeforcescompetitive-programmingconstructive-algorithmsgreedynumber-theory
CF 2171C1 - Renako Amaori and XOR Game (easy version)

Each test case gives two binary arrays of equal length. On position $i$, there is a pair of bits $(ai, bi)$. During the game, players go through indices from left to right.

codeforcescompetitive-programmingbitmasksgamesgreedy
CF 2171D - Rae Taylor and Trees (easy version)

We are asked to check whether a tree can be built from a permutation of numbers from 1 to n, subject to a specific ordering constraint.

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsugreedyimplementationtrees
CF 2171C2 - Renako Amaori and XOR Game (hard version)

We are asked to simulate a two-player game on two arrays of integers, a and b, each of length n. Players take turns: Ajisai moves on odd-numbered turns, Mai moves on even-numbered turns. On a player’s turn, they can swap the current element a[i] with b[i] or leave it as is.

codeforcescompetitive-programmingbitmasksgamesgreedy
CF 2171B - Yuu Koito and Minimum Absolute Sum

We are given an array of nonnegative integers with some entries marked as -1, representing blanks. Our task is to replace each blank with a nonnegative integer to minimize the absolute value of the sum of differences between consecutive elements.

codeforcescompetitive-programmingmath
CF 2171A - Shizuku Hoshikawa and Farm Legs

Error in message stream

codeforcescompetitive-programmingbrute-forcemath
CF 2172N - New Kingdom

We are asked to construct an undirected simple connected graph on $n$ labeled vertices. The graph must satisfy three structural constraints at the same time. First, it must be a single connected component without multi-edges or self-loops.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 2172M - Maximum Distance To Port

We have a network of cities connected by roads, where each road is exactly one kilometer long. Each city produces one type of agricultural product, and city 1 is a central port.

codeforcescompetitive-programminggraphsshortest-paths
CF 2172L - Maximum Color Segment

We have a rope consisting of n units, each colored either red or black. The rope is represented as a string of length n where each character is R or B. We are allowed to perform up to m operations.

codeforcescompetitive-programmingdpimplementation
CF 2172I - Birthday

We are asked to cut a circular cake, represented as a circle centered at the origin with radius r, into two pieces using a single straight line. On the cake are n strawberries, each strictly within 0.9 times the radius from the center.

codeforcescompetitive-programminggeometry
CF 2172K - Kindergarten Homework

Error in message stream

codeforcescompetitive-programmingimplementationstrings
CF 2172J - Sliding Tiles

We are given an $n times n$ grid with tiles stacked in columns and vertical bars between adjacent columns. Each column $i$ starts with $ai$ tiles stacked from the bottom.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdsu
CF 2172H - Shuffling Cards with Problem Solver 68!

We are given a deck of $2^k$ cards represented as a string of lowercase letters. The deck can be rotated by moving the first $m$ cards to the end. After this optional rotation, the deck is riffle-shuffled $t$ times.

codeforcescompetitive-programminghashingstring-suffix-structuresstrings
CF 2172G - Gene Editor

We are asked to count how many gene sequences of a given length can be obtained from an initial sequence using a specific set of mutations. The sequences only contain A and B, and mutations allow inserting or deleting AA, BBB, or a special substring s.

codeforcescompetitive-programming
CF 2172E - Number Maze

We are given a very small “number universe” built from the digits of a base number. The base number is always one of three possibilities: a two-digit number, a three-digit number, or a four-digit number.

codeforcescompetitive-programmingimplementation
CF 2172F - Cluster Computing System

We are given a sequence of $n$ servers, each with a database protocol type $pi$, which is a positive integer. Initially, the servers are disconnected.

codeforcescompetitive-programminggraphsgreedymath
CF 2172D - Divisor Card Game

We are asked to model a probabilistic card game where each student starts with a subset of numbered cards and additional cards are revealed one by one.

codeforcescompetitive-programmingcombinatoricsdp
CF 2172B - Buses

Every bus moves along the road at the same speed x. Bus i starts at position si at time 0, moves to the right, and disappears once it reaches ti. A person starts at position p. They can walk at speed y, where y < x.

codeforcescompetitive-programminggreedysortings
CF 2172A - ASCII Art Contest

We are given the scores of three AI-powered creative assistants-Gemini, ChatGPT, and Claude-in an ASCII art contest. Each score is an integer between 80 and 100. The organizers want to decide if the judges' scores are consistent enough to announce a final result.

codeforcescompetitive-programmingimplementation
CF 2172C - Circles Are Far from Each Other

We are asked to place a sequence of circles on a single straight line of centers, while controlling how they may overlap and nest inside each other. Each circle has a fixed radius, and the radii are given in non-increasing order.

codeforcescompetitive-programmingbinary-searchgreedy
CF 2173F - Isla's Memory Thresholds

We are given a non-increasing array of positive integers, and we repeatedly process subsegments of it under a “capacity reset” rule. For each query, we pick a contiguous slice from index l to r. We then scan it left to right, maintaining a running sum.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquermath
CF 2173E - Shiro's Mirror Duel

We maintain a permutation of 1..n. A query chooses two indices x and y. The judge then flips a coin. Either positions (x,y) are swapped, or their mirrored positions (n-x+1, n-y+1) are swapped.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractiveprobabilitiessortings
CF 2173D - Taiga's Carry Chains

Taiga is given a positive integer n and can perform exactly k moves. In each move, she chooses a power of two, 2^ℓ, and adds it to n. The score of each move is the number of binary carries that occur during the addition.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedymath
CF 2173A - Sleeping Through Classes

We are asked to plan our sleep schedule across a sequence of classes, each of which is either important or not. The day is represented as a binary string where '1' marks an important class and '0' a non-important one.

codeforcescompetitive-programminggreedyimplementation
CF 2173B - Niko's Tactical Cards

We process a sequence of turns. The current score starts at 0. At turn i, we are given two possible transformations: If we take the red card, the new score becomes k - k - a[i] If we take the blue card, the new score becomes k - b[i] - k We must choose exactly one…

codeforcescompetitive-programmingdpgreedymath
CF 2173C - Kanade's Perfect Multiples

We are given a multiset of numbers, all lying in the range from 1 to a large limit k. From this array we must construct a set B of distinct integers, also between 1 and k, but under two simultaneous constraints that interact in a non-trivial way.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedynumber-theory
CF 2174E2 - Game of Scientists (Version 2)

We are interacting with a hidden integer $x$ that is fixed for each game and always lies in the range $[1, c]$, where $c = 2 cdot 10^9$. Our goal is to determine this number using at most three queries. Each query chooses a base $b ge 2$.

codeforcescompetitive-programmingbinary-searchchinese-remainder-theoremdfs-and-similarinteractivemath
CF 2174F - Mosaic Tree

Working

codeforcescompetitive-programmingcombinatoricsdpfftmathtrees
CF 2174E1 - Game of Scientists (Version 1)

We are asked to guess a hidden number x between 1 and c by making queries about the sum of its digits in a chosen base. Each query specifies a base b (between 2 and c) and returns either the sum of digits of x in that base, or -1 if x is smaller than b.

codeforcescompetitive-programmingchinese-remainder-theoremconstructive-algorithmsinteractivemath
CF 2174D - Secret Message

We are asked to analyze a weighted undirected graph with n vertices and m edges. For each graph, we need to select n - 1 edges whose total weight is minimal, but these edges must not form a tree.

codeforcescompetitive-programmingdata-structuresdpgreedytrees
CF 2174C1 - Beautiful Patterns (Easy Version)

We are asked to compute the expected beauty of a linear mosaic of pebbles, where each pebble is painted in one of $m$ colors chosen independently and uniformly.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 2174C2 - Beautiful Patterns (Hard Version)

We are asked to calculate the expected beauty of a 1×n mosaic, where each cell is painted independently with one of m colors. Beauty is defined as the square of the number of palindromic subsegments. A subsegment is palindromic if it reads the same forwards and backwards.

codeforcescompetitive-programmingcombinatoricsmathprobabilities
CF 2174A - Needle in a Haystack

We are given two strings, s and t, both composed of lowercase English letters. The goal is to rearrange t in such a way that s appears at least once as a subsequence. Among all such valid rearrangements, we need to find the one that is lexicographically smallest.

codeforcescompetitive-programminggreedystringstwo-pointers
CF 2174B - Wishing Cards

We are building a sequence of numbers $b1, b2, ldots, bn$ representing how many wishing cards each friend will give, but each friend has an upper limit $ai$, and all $bi$ together cannot exceed a total budget $k$. Each $bi$ must stay within $0 le bi le ai$.

codeforcescompetitive-programmingdp
CF 2175A - Little Fairy's Painting

We are given a very long ribbon with $10^{18}$ cells, but only the first $n$ cells are already painted with specific colors. Each color is represented as an integer.

codeforcescompetitive-programmingimplementation
CF 2176B - Optimal Shifts

We are given a binary string consisting of 0s and 1s, with at least one 1. The goal is to transform this string into a string of all 1s. To achieve this, we can repeatedly choose a shift d and perform a cyclic right shift of the string by d.

codeforcescompetitive-programmingbitmasksgreedystrings
CF 2176F - Omega Numbers

We are given several arrays, and for each array we need to evaluate a sum over all unordered pairs of indices. For each pair of values $ai, aj$, we look at the number of distinct prime factors in their product and then raise that count to a fixed power $k$.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathnumber-theory
CF 2176E - Remove at the lowest cost

We are given an array of n elements. Each element has a value ai and a removal cost ci. The goal is to remove all elements except one, using a series of adjacent removals, paying the minimum total cost.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugreedyimplementationtrees
CF 2176D - Fibonacci Paths

We are given a directed graph with $n$ vertices, each labeled with a positive integer $av$, and $m$ edges. Our goal is to count all simple paths that include at least two vertices, where the sequence of numbers along the path forms a generalized Fibonacci sequence.

codeforcescompetitive-programmingdata-structuresdpgraphssortings
CF 2176C - Odd Process

We are given a multiset of coin values and asked to simulate a process that depends not only on which coins we pick, but also on the parity of the running sum inside a temporary bag.

codeforcescompetitive-programminggreedysortings
CF 2176A - Operations with Inversions

We are given an array of numbers, and we are allowed to repeatedly remove elements under a very specific condition. Each move chooses two indices $i < j$ such that the value at $i$ is strictly larger than the value at $j$, and then deletes the element at position $j$.

codeforcescompetitive-programminggreedyimplementationmath
CF 2178H - Create or Duplicate

Santa starts with exactly one present of each of three values, $a$, $b$, and $c$. Let the current counts of these present types be $xa$, $xb$, and $xc$. Initially all three counts are equal to $1$. Two operations are available.

codeforcescompetitive-programmingbitmasksgraphsnumber-theoryshortest-paths
CF 2178I - Numbers or Fireworks

We are given a set of cities on a Cartesian grid, each at distinct lattice points, and an integer $k$. The task is to compute a certain "explosiveness" measure over all proper subsets of cities.

codeforcescompetitive-programmingbitmaskscombinatoricsdpgraphs
CF 2178G - deCH OR Dations

We are given a circle with $2n$ points labeled from $1$ to $2n$. Santa draws $n$ chords connecting distinct pairs of points. Chords may intersect. For each prefix of chords $1$ through $ell$, we are asked whether the chords are tight-knit.

codeforcescompetitive-programmingbitmasksdata-structuresdphashingprobabilities
CF 2178E - Flatten or Concatenate

We are asked to determine the maximum element of a hidden array that was generated from an initial array containing a single power-of-two number.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractive
CF 2178F - Conquer or of Forest

We are given a rooted tree with vertices numbered from 1 to $n$. Each vertex is colored based on the size of its subtree: if the subtree size is even, the vertex is white; otherwise, it is black.

codeforcescompetitive-programmingcombinatoricsmathtrees
CF 2178D - Xmas or Hysteria

We are given a village of n elves, each with an initial health equal to its attack value. The elves engage in a Mass Hysteria event where each elf that has not attacked yet can choose another living elf to attack.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 2178B - Impost or Sus

We start with a string consisting only of s and u. We may repeatedly choose any position containing u and change it into s. We are not allowed to change an s back into u. The final string must satisfy two conditions. First, it must contain at least two occurrences of s.

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 2178C - First or Second

We have a line of children, each with an integer niceness value. Santa wants to assign each child to either a nice list or a naughty list, but he can only remove children from the front of the line.

codeforcescompetitive-programmingdpgreedyimplementation
CF 2178A - Yes or Yes

We are given a string consisting only of two symbols, where one behaves like a neutral value and the other behaves like an absorbing “true” value under an OR-like merge operation.

codeforcescompetitive-programminggreedystrings
CF 2179G - Blackslex and Penguin Migration

We are asked to reconstruct the positions of penguins on an $n times n$ grid after a migration, knowing only the Manhattan distances between pairs of penguins.

codeforcescompetitive-programmingbrute-forceinteractivemath
CF 2179H - Blackslex and Plants

We are given a line of plants indexed from 1 to n, all initially holding zero water. Each query specifies a segment $[l, r]$, and for every position $i$ in that segment we add a value that depends on how far $i$ is from $l$.

codeforcescompetitive-programmingbitmasksdata-structuresdpimplementationmath
CF 2179A - Blackslex and Password

We are asked to determine, for given integers $k$ and $x$, the smallest string length $n$ for which no valid password exists under specific rules. Each password uses only the first $k$ lowercase letters.

codeforcescompetitive-programmingmathstrings
CF 2179F - Blackslex and Another RGB Walking

We are asked to solve a two-part communication problem on a connected bipartite graph. In the first part, the agent colors vertices using three colors to encode directional information.

codeforcescompetitive-programmingcommunicationconstructive-algorithmsgraphsinteractivenumber-theorytrees
CF 2179E - Blackslex and Girls

We are asked to divide voters into districts according to a binary pattern while respecting minimum district sizes. Specifically, we have two parties, A and B, with a total of x and y voters, respectively.

codeforcescompetitive-programmingconstructive-algorithmsgeometrymath
CF 2179D - Blackslex and Penguin Civilization

We are asked to construct a permutation of all integers from $0$ to $2^n - 1$. The quality of a permutation is defined through a running process over prefixes: we maintain the bitwise AND of the prefix seen so far, and at each step we add the number of set bits in that AND…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 2179C - Blackslex and Number Theory

Working

codeforcescompetitive-programmingimplementationmathnumber-theorysortings
CF 2179B - Blackslex and Showering

We are given a sequence of floors that Blackslex needs to visit in order, and moving between floors takes time proportional to the absolute difference between consecutive floors. Blackslex can skip at most one floor in the sequence.

codeforcescompetitive-programmingdpgreedyimplementation
CF 2180H2 - Bug Is Feature (Conditional Version)

Each game starts from three numbers forming an arithmetic progression, so the state can always be described as $(a, a+d, a+2d)$ with $d 0$. The players repeatedly pick one coordinate and increase it, but the triple must remain an arithmetic progression after every move.

codeforcescompetitive-programminggames
CF 2180H1 - Bug Is Feature (Unconditional Version)

Working

codeforcescompetitive-programminggames
CF 2180F1 - Control Car (Easy Version)

The grid in this problem is best thought of as a lattice of junction points, not cells. Every intersection point on the grid is assigned one of four directions. From each such point, we draw a unit segment in its chosen direction.

codeforcescompetitive-programmingcombinatoricsdpprobabilities
CF 2180G - Balance

We maintain a sequence that starts empty and evolves through three kinds of operations. One operation deletes the middle element of the current sequence, where the middle is defined as the ceiling of half the current length.

codeforcescompetitive-programmingbitmaskscombinatoricsimplementationmath
CF 2180E - No Effect XOR

We have frogs on every integer position inside a contiguous segment $[l,r]$. After choosing a positive integer $x$, every frog moves from position $i$ to position $i oplus x$. XOR with a fixed value is a permutation of all non-negative integers.

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpgreedymath
CF 2180F2 - Control Car (Hard Version)

We are asked to count the number of ways to assign directions to the corners of an $n times m$ grid so that a simulated car starting at the top-left cell eventually stops inside the grid.

codeforcescompetitive-programmingcombinatoricsdpmatricesprobabilities
CF 2180D - Insolvable Disks

We are given a set of points on a line, each point representing the center of a disk we must draw. Every disk has a positive radius, and no two disks can overlap, though touching at the edges is allowed.

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 2180C - XOR-factorization

We are asked to take an integer $n$ and split it into exactly $k$ non-negative integers whose bitwise XOR equals $n$. Among all such splits, we want one that maximizes the sum of the numbers. Each number in the split must be between 0 and $n$ inclusive.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedynumber-theory
CF 2180A - Carnival Wheel

We are given a circular prize wheel with l numbered sections from 0 to l-1. The wheel pointer starts at a section a. Each spin moves the pointer forward by exactly b positions modulo l.

codeforcescompetitive-programmingbrute-forcenumber-theory
CF 2180B - Ashmal

We are given a sequence of strings, and we must insert them one by one into an initially empty string. Each new string can be placed either at the left end or the right end of the current result. After all insertions, we obtain a single final string.

codeforcescompetitive-programminggreedystrings
CF 2181M - Medical Parity

We are given two binary strings, which we can think of as observed measurements from a medical test. The first string represents the recorded presence or absence of reactions to several allergens.

codeforcescompetitive-programmingdpstrings
CF 2181L - LLM Training

We are given several token sequences, each sequence representing a text where some positions are produced by a language model and others are written directly by a user. Only the positions marked as generated contribute to the training loss.

codeforcescompetitive-programmingmathstring-suffix-structures
CF 2181K - Knit the Grid

The canvas is a rectangular grid of cells, but the real structure lives on its grid graph: vertices are grid intersection points and edges connect adjacent intersections horizontally or vertically. Initially, some collection of simple cycles is drawn along these edges.

codeforcescompetitive-programming2-satconstructive-algorithmsgraphsmatrices
CF 2181I - Irrigation Interlock

We have two sets of points on a Cartesian plane: pumps scattered across a valley and reservoirs positioned on surrounding hills.

codeforcescompetitive-programminggeometry
CF 2181J - Jinx or Jackpot

We are given a casino machine whose behaviour is determined by one hidden probability value. There is an array of probabilities, and the casino owner secretly picks one index uniformly at random at the start and fixes it forever.

codeforcescompetitive-programmingbrute-forcedpmathprobabilities
CF 2181H - Honey Cake

We are given a rectangular cake with dimensions $w times h times d$. The goal is to divide this solid into exactly $n$ smaller rectangular pieces, all identical in size. The only allowed operations are cuts that are parallel to the faces of the cake.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 2181G - Greta's Game

Each round produces a choice of an integer at every position on a cycle. After the numbers are chosen, we look at each adjacent pair on the cycle and award one point to both endpoints whenever the left endpoint is strictly larger than the right endpoint.

codeforcescompetitive-programmingbinary-searchdpgraphsgreedymath
CF 2181E - Elevator Against Humanity

We have a skyscraper with floors numbered from 1 up to very large numbers, and several people waiting for an elevator on different floors. Each person has a distinct starting floor and a distinct destination floor, and no two floors overlap.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedysortings
CF 2181F - Fragmented Nim

We are asked to analyze a variation of the classical game of Nim. In the original Nim, players take turns picking a pile and removing any number of stones. The player who takes the last stone wins.

codeforcescompetitive-programminggames
CF 2181D - Doorway

Each layer of the doorway is a one-dimensional segment between two fixed walls. Inside that segment, there are several rigid door blocks placed in a line, but each block is allowed to slide left or right as long as it does not overlap other blocks or cross the walls.

codeforcescompetitive-programmingbinary-searchdata-structuressortings
CF 2181A - Alphabet City

We are asked to calculate how many full sets of street signs can be made when one street's order is missing. Each street in Alphabet City has a name made from capital letters, and each street has an order for m identical signs.

codeforcescompetitive-programmingbinary-searchmathstrings
CF 2181B - Battle of Arrays

We are asked to simulate a turn-based game between Alice and Bob. Each player starts with an array of positive integers. On their turn, a player picks any element from their own array and applies it against the maximal element in the opponent's array.

codeforcescompetitive-programmingdata-structuresgamesgreedy
CF 2181C - Cacti Classification

We are dealing with a hidden connected graph that has a very restricted structure: it is a cactus, meaning every edge participates in at most one simple cycle.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsinteractivemath
CF 2182G - Short Garland

We are given a rooted tree with vertex 1 fixed as the root. A sequence of n “placements” must be assigned, one for each vertex of the tree, but the twist is that the placement order is not arbitrary. The first placement is forced onto the root.

codeforcescompetitive-programmingcombinatoricsdata-structuresdfs-and-similardptrees
CF 2182F2 - Christmas Reindeer (hard version)

We have a dynamic herd of reindeer, each with strength $2^{ci}$, and we need to answer three types of queries: adding a reindeer, removing a reindeer, or counting how many subsets of the herd meet a certain carrying capacity threshold.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdata-structuresgreedymath
CF 2182E - New Year's Gifts

Monocarp wants to make as many friends happy as possible with a limited budget. He has a number of friends and a set of boxes.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortingstwo-pointers
CF 2182F1 - Christmas Reindeer (easy version)

We maintain a multiset of reindeer. Each reindeer is identified by a power level, but the real value that matters is a power of two, $2^{ci}$.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdpmath
CF 2182D - Christmas Tree Decoration

We are given several independent scenarios. In each scenario, there are $n$ people and $n+1$ boxes of decorations. Box $0$ is special, and each person $i$ has their own personal box $i$. Each box starts with some number of decorations.

codeforcescompetitive-programmingcombinatoricsdpgreedymath
CF 2182A - New Year String

We are given a string composed of the characters 0, 2, 5, and 6. A string is considered a New Year string if it either contains the substring 2026 somewhere or does not contain the substring 2025 at all.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationstrings
CF 2182B - New Year Cake

We are asked to help Monocarp bake a layered cake under two constraints: the size of each layer grows exponentially and the chocolate covering each layer must alternate between white and dark. The top layer always has size 1.

codeforcescompetitive-programmingbrute-force
CF 2182C - Production of Snowmen

We are given three circular sequences of equal length, each representing sizes of snowballs on a conveyor belt. From each conveyor we choose a starting position, and then we simultaneously walk forward step by step around all three cycles.

codeforcescompetitive-programmingbrute-forcecombinatoricsdp
CF 2183I2 - Pairs Flipping (Hard Version)

We are given a binary string where each position contains either a 0 or a 1. We are allowed a fixed number of operations, exactly one for each value from 1 up to half the length of the string.

codeforcescompetitive-programmingconstructive-algorithms
CF 2183I1 - Pairs Flipping (Easy Version)

We are working with a binary string where each position holds either a 0 or a 1, and we are allowed to repeatedly apply a very specific kind of operation. Each operation is indexed from 1 upward, and on operation number x we may choose a starting position l.

codeforcescompetitive-programmingconstructive-algorithms
CF 2183G - Snake Instructions

The interactive version allows us to ask up to three carefully chosen instructions and observe the surviving snakes. In the hacked version, the speeds are already given in the input, and our job is to reproduce the answer that an optimal interactive solution would output.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractive
CF 2183H - Minimise Cost

We are given an array of integers and asked to divide it into exactly $k$ non-empty subsequences. For any subsequence $b$, its cost is defined as the product of its length and the sum of its elements. Our goal is to minimize the total cost across all $k$ subsequences.

codeforcescompetitive-programmingbinary-searchdpgreedysortings
CF 2183F - Jumping Man

We are given a rooted tree with each node labeled by a lowercase letter. For each node $i$, we are asked to analyze all strings that can be formed by starting at any node in the subtree of $i$ and repeatedly jumping to a proper descendant, concatenating the letters along the…

codeforcescompetitive-programmingbrute-forcecombinatoricsdfs-and-similardptrees
CF 2183E - LCM is Legendary Counting Master

We are given a sequence of length $n$ where some positions are fixed numbers between $1$ and $m$, and some positions are zero placeholders that must be filled. After filling all zeros with values in $[1, m]$, the resulting sequence must satisfy two conditions at the same time.

codeforcescompetitive-programmingdpmathnumber-theory
CF 2183D2 - Tree Coloring (Hard Version)

We are given a rooted tree, where all nodes are initially white, and we need to color all nodes black in the minimum number of operations.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdata-structuresdfs-and-similargreedyimplementationtrees
CF 2183D1 - Tree Coloring (Easy Version)

We are given a rooted tree with n vertices, where the root is vertex 1, and initially all vertices are white. The distance di of a vertex i is the number of edges on the path from the root to i.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedytrees
CF 2183B - Yet Another MEX Problem

We are given an array of non-negative integers and a number $k$. The task is to repeatedly remove elements from the array, always choosing a window of length $k$ whose MEX is maximal, and deleting any element within that window.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2183C - War Strategy

We have a linear arrangement of bases numbered from 1 to n. Our home base is at position k, and we start with exactly one soldier there. Every day, we can select a base and move any number of soldiers from it either left or right by exactly one position.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers