brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1673F - Anti-Theft Road Planning

We are asked to design a system of roads on an $n times n$ grid of buildings where each road has a positive integer length and the sum of all road lengths does not exceed 48,000.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedyinteractivemath
CF 1673E - Power or XOR?

We are given a sequence of integers $B1, B2, dots, Bn$. Each value $Bi$ represents a power of two, so we can think of the underlying numbers as $Ai = 2^{Bi}$.

codeforcescompetitive-programmingbitmaskscombinatoricsmathnumber-theory
CF 1673D - Lost Arithmetic Progression

We are given two arithmetic progressions, $B$ and $C$. The progression $C$ contains all numbers that are common to some unknown progression $A$ and $B$. Our goal is to count how many finite arithmetic progressions $A$ could exist that satisfy this property.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1673B - A Perfectly Balanced String?

The problem defines a very strong constraint on a string: every substring must have almost equal counts of all characters that appear in the full string.

codeforcescompetitive-programmingbrute-forcegreedystrings
CF 1673A - Subtle Substring Subtraction

We are given several independent rounds. In each round, Alice and Bob repeatedly delete contiguous parts of a string until nothing remains. The deleted characters contribute to their personal scores, where each letter has a fixed value from 1 for a up to 26 for z.

codeforcescompetitive-programminggamesgreedystrings
CF 1674A - Number Transformation

Thank you for providing the detailed sample input and output. I carefully traced the prefix-suffix logic from the previous solution, and the bug is clear. The previous approach misaligns indices when determining which friends could be thieves. Specifically: 1.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1674G - Remove Directed Edges

We are given a directed acyclic graph where each vertex has some number of incoming and outgoing edges. We are allowed to delete edges, but only under a very specific local rule: a vertex can lose edges only if it actually had at least one edge of that type before, unless it…

codeforcescompetitive-programmingdfs-and-similardpgraphs
CF 1674F - Desktop Rearrangement

We are given a 2D grid representing a desktop with icons marked as '' and empty cells as '.'. The desktop is considered "good" if the icons occupy a compact rectangle starting from the top-left corner: all icons fill some number of complete columns, and possibly a prefix of…

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1674D - A-B-C Sort

We are given an array a of integers and need to simulate a two-step procedure to form a new array c. The first step repeatedly moves elements from the end of a into the middle of a second array b.

codeforcescompetitive-programmingconstructive-algorithmsimplementationsortings
CF 1674E - Breaking the Wall

We are given a row of wall segments, each with some durability. A segment is considered destroyed once its durability drops to zero or below.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedymath
CF 1674B - Dictionary

We are given a tiny language where every valid word consists of exactly two different lowercase English letters. Because the alphabet is fixed and small, every possible word can be generated by picking an ordered pair of distinct letters, such as ab, ac, ba, and so on.

codeforcescompetitive-programmingcombinatoricsmath
CF 1674C - Infinite Replacement

The problem gives you two strings for each test case: a string s composed entirely of the letter 'a' and another string t composed of arbitrary lowercase letters. You are allowed to repeatedly replace any single 'a' in s with the string t.

codeforcescompetitive-programmingcombinatoricsimplementationstrings
CF 1675C - Detective Task

We observe a sequence of visitors entering a room one after another. Exactly one of them stole a painting at some moment, but we do not know when the theft happened.

codeforcescompetitive-programmingimplementation
CF 1675G - Sorting Pancakes

The array represents stacks of pancakes placed on a row of dishes. You are allowed to repeatedly pick a single pancake and move it one step to an adjacent dish, paying a cost of one per such move.

codeforcescompetitive-programmingdp
CF 1675F - Vlad and Unfinished Business

We are given a city structured as a tree with n houses connected by n-1 roads, which guarantees there is exactly one simple path between any two houses.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
CF 1675D - Vertical Paths

We are given a rooted tree, but the root is not explicitly provided. Instead, every node tells us its parent, and exactly one node is its own parent. That node is the root. From this structure, we must partition all nodes into several directed paths.

codeforcescompetitive-programminggraphsimplementationtrees
CF 1675E - Replace With the Previous, Minimize

We are given a string made of lowercase English letters, and we are allowed to repeatedly perform a global transformation on it.

codeforcescompetitive-programmingdsugreedystrings
CF 1675B - Make It Increasing

We are given several independent arrays. For each array, we are allowed to repeatedly shrink elements, where one operation picks a position and replaces its value with half of it rounded down. No swapping is allowed, so the order of elements is fixed.

codeforcescompetitive-programminggreedyimplementation
CF 1675A - Food for Animals

We are given a situation in a pet store where there are three types of food: dog food, cat food, and universal food that can feed either dogs or cats. Polycarp owns a certain number of dogs and cats. Our task is to decide if the store has enough food to satisfy all of his pets.

codeforcescompetitive-programminggreedymath
CF 1676H1 - Maximum Crossings (Easy Version)

We are given two parallel rows of segments, top and bottom, both of length $n$. Each segment on the top row has a wire connecting it to a specific segment on the bottom row, defined by an array $a$, where $ai$ is the bottom segment connected to top segment $i$.

codeforcescompetitive-programmingbrute-force
CF 1676H2 - Maximum Crossings (Hard Version)

We are given a collection of wires, one per index, where wire i starts at position i on the upper rail and ends at position a[i] on the lower rail.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortings
CF 1676B - Equal Candies

We are given a set of boxes, each containing some number of candies. There is exactly one box for each friend, and the goal is to make all boxes contain the same number of candies so that no friend feels left out. We can only eat candies from a box; we cannot add any.

codeforcescompetitive-programminggreedymathsortings
CF 1676G - White-Black Balanced Subtrees

We are given a rooted tree where vertex 1 is the root. Every vertex is colored either black or white. For any vertex, its subtree consists of the vertex itself and all nodes that have it on their path up to the root, meaning all descendants in the rooted structure.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 1676F - Longest Strike

We are given an array of integers and a threshold number $k$. Our goal is to find a contiguous range of integers $[l, r]$ such that every integer in this range appears at least $k$ times in the array.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortingstwo-pointers
CF 1676D - X-Sum

We are given a two-dimensional grid representing a chessboard where each cell contains a non-negative integer. A bishop can be placed on any cell, and it attacks all cells along the four diagonals that intersect at its position. The cell the bishop occupies counts as attacked.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1676E - Eating Queries

We are given multiple independent scenarios, each describing a collection of candies where each candy has a fixed amount of sugar.

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1676C - Most Similar Words

We are given a collection of words where each word has the same length. Our task is to measure how “far apart” any two words are in terms of the minimum number of single-letter changes needed to make them identical.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathstrings
CF 1676A - Lucky?

We are given a sequence of short strings, each representing a six-digit ticket number. Each ticket should be split into two halves of equal length. The task is to decide whether the sum of digits in the left half matches the sum of digits in the right half.

codeforcescompetitive-programmingimplementation
CF 1677B - Tokitsukaze and Meeting

We are asked to simulate a dynamic seating scenario. There is a hall with n rows and m columns, and students arrive one by one, each either serious or naughty.

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 1677F - Tokitsukaze and Gems

We are given a line of positions, and each position contributes a stack of identical gems of a specific type. Position i holds ai gems of type i.

codeforcescompetitive-programmingdpmath
CF 1677D - Tokitsukaze and Permutations

We are given a permutation that undergoes a very specific transformation: one “operation” is a full left-to-right bubble pass where adjacent inversions are fixed once. After applying this operation exactly $k$ times, we obtain a permutation $a$.

codeforcescompetitive-programmingdpmath
CF 1677E - Tokitsukaze and Beautiful Subsegments

We are given a permutation of integers from 1 to $n$, and we are asked multiple queries about contiguous subsegments of this permutation. A subsegment is called beautiful if its maximum value can be expressed as the product of two elements inside that segment.

codeforcescompetitive-programmingdata-structures
CF 1677C - Tokitsukaze and Two Colorful Tapes

Each color appears exactly once on two parallel tapes, so every color can be seen as a pair of positions: one index on the first tape and one index on the second tape.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1677A - Tokitsukaze and Strange Inequality

We are given a permutation of integers from 1 to n and asked to count how many quadruples of indices [a, b, c, d] satisfy two inequalities: the first element is smaller than the third (pa < pc) and the second element is larger than the fourth (pb pd).

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 1678B2 - Tokitsukaze and Good 01-String (hard version)

We are given a binary string of even length and asked to transform it into a "good" string. A good string is defined by two rules.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1678A - Tokitsukaze and All Zero Sequence

The problem asks us to turn a sequence of numbers into all zeros using a particular operation. In each operation, we pick two distinct elements. If they are equal, we replace one of them with zero. If they are different, we replace both with the smaller of the two.

codeforcescompetitive-programmingimplementation
CF 1678B1 - Tokitsukaze and Good 01-String (easy version)

We are given a binary string and allowed to flip any individual character at unit cost. After all changes, the string is interpreted by compressing it into maximal runs of identical characters.

codeforcescompetitive-programmingimplementation
CF 1679F - Formalism for Formalism

We are given a length $n$ string of decimal digits, and a set of constraints between digits in the form of allowed adjacent swaps.

codeforcescompetitive-programmingbitmasksdpmath
CF 1679E - Typical Party in Dorm

We are given a string of length n composed of the first 17 lowercase letters (a through q) and question marks. Each question mark acts as a wildcard that can be replaced by a letter from a specific set provided in a query.

codeforcescompetitive-programmingbitmaskscombinatoricsdpstrings
CF 1679D - Toss a Coin to Your Graph...

The problem gives a directed graph where each vertex has a positive integer value. Masha can place a coin on any vertex, and then move it along the graph edges exactly $k-1$ times. Every time the coin visits a vertex, the vertex’s number is recorded in a notebook.

codeforcescompetitive-programmingbinary-searchdfs-and-similardpgraphs
CF 1679A - AvtoBus

We are asked to determine how many buses a fleet could have given the total number of wheels. Each bus comes in one of two types: two-axle buses with 4 wheels and three-axle buses with 6 wheels.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1679B - Stone Age Problem

We are given an array of integers and a sequence of queries. Each query either replaces a single element in the array with a new value or replaces every element in the array with the same value. After each query, we need to report the sum of the array.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1679C - Rooks Defenders

We are asked to simulate a sequence of operations on an $n times n$ chessboard involving rooks. Each rook attacks its entire row and column.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1680A - Minimums and Maximums

We are asked to construct arrays called beautiful arrays. A beautiful array is one in which the number of elements equal to the minimum value falls between two given bounds, $l1$ and $r1$, and the number of elements equal to the maximum value falls between two bounds, $l2$ and…

codeforcescompetitive-programmingbrute-forcemath
CF 1680F - Lenient Vertex Cover

We are asked to find a lenient vertex cover for a connected undirected graph. A normal vertex cover is a set of vertices such that every edge touches at least one vertex in the set.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdsugraphstrees
CF 1680D - Dog Walking

We are given a sequence of movements of a dog along an infinite line. Each minute, the dog moves a certain distance. Positive numbers move it to the right, negative to the left, and zero indicates unknown movement where we can pick any integer in the range $[-k, k]$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1680E - Moving Chips

We are given a $2 times n$ board where some cells contain chips, represented by '', and others are empty, represented by '.'. Our task is to move chips so that exactly one chip remains on the board.

codeforcescompetitive-programmingbitmasksdpgreedy
CF 1680B - Robots

We are given a small rectangular grid, with each cell either empty or containing a robot. Robots can move simultaneously in one of four cardinal directions, and if any robot tries to leave the grid, it explodes.

codeforcescompetitive-programmingimplementation
CF 1680C - Binary String

We are given a binary string and we are allowed to cut it in a very specific way: we choose some prefix and suffix to remove, leaving a single contiguous substring in the middle. The remaining substring is what we “keep”, while everything outside it is considered removed.

codeforcescompetitive-programmingbinary-searchgreedystringstwo-pointers
CF 1681A - Game with Cards

Two players each hold a multiset of integers. They play a turn-based game where the only rule is that every newly played number must be strictly larger than the previous one.

codeforcescompetitive-programminggamesgreedy
CF 1681F - Unique Occurrences

We are given a tree with $n$ vertices. Each edge has an integer label. For any pair of vertices $v$ and $u$, we define $f(v, u)$ as the number of edge labels that appear exactly once along the unique path connecting $v$ and $u$.

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquerdpdsutrees
CF 1681E - Labyrinth Adventures

We are given a labyrinth structured as concentric layers in an $n times n$ grid. Each layer is a contiguous set of cells surrounding the previous layer. The first layer is just the bottom-left corner.

codeforcescompetitive-programmingdata-structuresdpmatricesshortest-paths
CF 1681D - Required Length

We are given an integer x and a target length n. We can repeatedly choose any digit y from the current number x and multiply x by y. The goal is to make x have exactly n digits using the minimum number of such operations.

codeforcescompetitive-programmingbrute-forcedfs-and-similardphashingshortest-paths
CF 1681C - Double Sort

We are given two arrays of the same length, a and b. We can perform a special swap operation: choose any two positions i and j, and simultaneously swap a[i] with a[j] and b[i] with b[j].

codeforcescompetitive-programmingimplementationsortings
CF 1681B - Card Trick

We are given a deck of n cards with distinct integer values, ordered from top to bottom. We then perform m shuffle operations, each defined by a number bj.

codeforcescompetitive-programmingimplementationmath
CF 1682D - Circular Spanning Tree

We are asked to construct a tree on n nodes arranged in a circle. Each node has a requirement: its degree must be even or odd, depending on the corresponding character in a binary string s.

codeforcescompetitive-programmingconstructive-algorithmsimplementationtrees
CF 1682F - MCMF?

We are given a sorted array a and an integer array b. Each query gives a segment [l, r], and we only care about it if the sum of b over this segment is zero. This condition guarantees that total “supply” and “demand” inside the segment balance perfectly.

codeforcescompetitive-programmingdata-structuresflowsgraphsgreedysortingstwo-pointers
CF 1682E - Unordered Swaps

We are given a permutation of integers from $1$ to $n$ and a set of $m$ swaps, which are guaranteed to be the minimum swaps required to sort the permutation. These swaps have been shuffled arbitrarily.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedymathsortingstrees
CF 1682B - AND Sorting

We are given a permutation of the integers from 0 to n−1, and we are allowed to rearrange it using a very unusual swap rule. A swap between two positions is only allowed when the bitwise AND of the two values currently stored at those positions equals a chosen value X.

codeforcescompetitive-programmingbitmasksconstructive-algorithmssortings
CF 1682A - Palindromic Indices

We are given a string that is already a palindrome, meaning it reads the same from left to right and right to left. For each position in this string, we imagine removing exactly one character and then ask whether the remaining string is still a palindrome.

codeforcescompetitive-programminggreedystrings
CF 1682C - LIS or Reverse LIS?

We are given several test cases. Each test case provides a multiset of numbers, and we are allowed to rearrange them in any order we want. After choosing an ordering, we look at two sequences: the chosen array itself, and its reverse.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1684H - Hard Cut

We are given a binary string, which is a sequence of '0's and '1's. Our task is to partition this string into contiguous substrings in such a way that, if we interpret each substring as a binary number and sum them all, the result is a power of two.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardivide-and-conquermath
CF 1684G - Euclid Guess

We are given a multiset of positive integers, and we are told that this multiset was produced by repeatedly running Euclid’s algorithm on several unknown integer pairs.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraph-matchingsmathnumber-theory
CF 1684D - Traps

We are given a sequence of traps, each with a base damage value. We traverse the traps in order, and for each trap we either take its damage or skip it by jumping over it.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1684F - Diverse Segments

We are given an array and several queries, where each query describes a segment of indices. The requirement is that inside every given query segment, all values must be pairwise distinct. If the array already satisfies this condition for all segments, we do nothing.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1684E - MEX vs DIFF

We are given an array of non-negative integers and we are allowed to perform up to k replacements, where each replacement changes any element to any non-negative value. After these edits, we evaluate the array using two quantities.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1684B - Z mod X = C

We are asked to construct three positive integers $x, y, z$ given three constraints on remainders. Each constraint relates one number to another through a modulo operation: the remainder when dividing $x$ by $y$ must equal $a$, the remainder when dividing $y$ by $z$ must equal…

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1684C - Column Swapping

We are given a matrix where each row represents a sequence of numbers arranged across columns. The goal is to make every row individually non-decreasing from left to right, but we are only allowed a single global operation: swap two entire columns.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationsortings
CF 1684A - Digit Minimization

We are given an integer with no zero digits, and two players, Alice and Bob, play a turn-based game on its digits. Alice always moves first and can swap any two digits at different positions. Bob always removes the last digit of the number.

codeforcescompetitive-programmingconstructive-algorithmsgamesmathstrings
CF 1685D2 - Permutation Weight (Hard Version)

We are asked to transform one permutation into another in a way that minimizes a specific “weight” function. The weight is the sum of absolute differences between each element of the new permutation and the element of the original permutation located at the next position in…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1685E - The Ultimate LIS Problem

We are given a permutation of size $2n+1$, and this array keeps changing through swaps of two positions. After every swap, we are not asked to analyze the array itself directly, but to consider all its cyclic rotations and determine whether at least one rotation has a…

codeforcescompetitive-programmingdata-structuresgreedy
CF 1685D1 - Permutation Weight (Easy Version)

We are given a permutation p of the numbers from 1 to n, and our task is to construct another permutation q of the same numbers that minimizes a specific weight function.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsu
CF 1685A - Circular Local MiniMax

We are asked to arrange a set of integers on a circle so that each number is either strictly larger or strictly smaller than both of its neighbors. The input consists of multiple test cases. Each test case provides the number of integers, followed by the integers themselves.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1685B - Linguistics

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programminggreedyimplementationsortingsstrings
CF 1685C - Bring Balance

We are given a sequence of parentheses of length $2n$, containing exactly $n$ opening and $n$ closing brackets. The task is to transform this sequence into a correct balanced parentheses string using the minimum number of operations, where each operation consists of reversing…

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1686B - Odd Subarrays

We are given a permutation of the numbers from 1 to n. We may split this permutation into any number of consecutive pieces. Each piece is a subarray. For every subarray, we look at its inversion count. A subarray is called odd if its inversion count is odd.

codeforcescompetitive-programmingdpgreedy
CF 1686A - Everything Everywhere All But One

We are given several independent test cases. Each test case starts with an array of integers. The only operation allowed transforms the array in a very specific way: we pick exactly one element to leave untouched and replace every other element by the average of the chosen group.

codeforcescompetitive-programminggreedy
CF 1687F - Koishi's Unconscious Permutation

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programmingfftmath
CF 1687D - Cute number

For every integer, look at the two consecutive perfect squares surrounding it. If $$m^2 le x < (m+1)^2,$$ then $g(x)=m^2$ and $f(x)=(m+1)^2$. The number is called cute when it is strictly closer to the lower square than to the upper square.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdsuimplementationmath
CF 1687E - Become Big For Me

We are given a sequence of integers a and a number v initialized to 1. The task is to perform a series of operations on v so that it becomes the greatest common divisor of all pairwise products of elements from a.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgreedymathnumber-theory
CF 1687C - Sanae and Giant Robot

The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdsugreedysortings
CF 1687A - The Enchanted Forest

We are asked to compute the maximum number of mushrooms Marisa can collect in a one-dimensional forest over a limited number of minutes.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1687B - Railway System

We are given a railway network consisting of n stations and m bidirectional tracks, each with a positive length. The network may not be fully connected and can have multiple tracks between the same pair of stations.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyinteractivesortings
CF 1688C - Manipulating History

We are asked to reconstruct the initial string of length 1 from which a sequence of operations produced a given final string. Each operation consists of selecting a substring of the current string and replacing it with another string, possibly of different length.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1688A - Cirno's Perfect Bitmasks Classroom

We are given a positive integer $x$, and the task is to find the smallest positive integer $y$ such that two bitwise conditions hold simultaneously: the bitwise AND of $x$ and $y$ is greater than zero, and the bitwise XOR of $x$ and $y$ is also greater than zero.

codeforcescompetitive-programmingbitmasksbrute-force
CF 1688B - Patchouli's Magical Talisman

We are asked to transform a collection of magical tokens so that every token has an odd magical power. Each token starts with some positive integer power.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedysortings
CF 1689B - Mystic Permutation

We are given a permutation $p$ of the numbers $1$ through $n$. We want to construct another permutation $q$ using the same numbers such that every position changes. For every index $i$, the value placed in $qi$ must be different from $pi$.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1689E - ANDfinity

We are given an array of non-negative integers. Each array element corresponds to a vertex in a graph. Two vertices are connected by an edge whenever the bitwise AND of their values is positive. The graph is not guaranteed to be connected.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdfs-and-similardsugraphs
CF 1689D - Lena and Matrix

We are given a grid of size $n times m$, where each cell is either black or white. Our task is to pick a cell such that the maximum Manhattan distance from this cell to any black cell is minimized.

codeforcescompetitive-programmingdata-structuresdpgeometryshortest-paths
CF 1689C - Infected Tree

We are given a binary tree rooted at vertex 1. Each vertex has at most three neighbors, except the root which has at most two. Initially, only the root is infected.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1689A - Lex String

We are given two strings, a and b, which do not share any letters. We can build a new string c by repeatedly taking the smallest available letter from either a or b. However, there is a restriction: we cannot take more than k characters from the same string consecutively.

codeforcescompetitive-programmingbrute-forcegreedyimplementationsortingstwo-pointers
CF 1690G - Count the Trains

Each carriage has its own maximum speed. When all carriages start moving, a carriage cannot move faster than any carriage in front of it, so its actual speed becomes the minimum value seen so far from the left.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedysortings
CF 1690C - Restoring the Duration of Tasks

We are given two increasing arrays. The array s contains the arrival time of each task. Task i becomes available at time s[i]. The array f contains the completion time of each task. Task i finishes exactly at time f[i]. Polycarp processes tasks in FIFO order.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1690F - Shifting String

We are given a string s of length n and a permutation p of the integers from 1 to n. Each permutation p defines a reordering operation: after one application, the character at position i in the new string moves to position p[i].

codeforcescompetitive-programminggraphsmathnumber-theorystrings
CF 1690E - Price Maximization

We are given an even number of goods, each with a weight, and we need to pack them into pairs. The cost of a pair is calculated by taking the sum of its weights, dividing by a fixed number $k$, and rounding down to the nearest integer.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers
CF 1690D - Black and White Stripe

We are given a stripe of tiles, each either white or black, and the goal is to ensure that at least one segment of exactly k consecutive tiles is entirely black.

codeforcescompetitive-programmingimplementationtwo-pointers
CF 1690B - Array Decrements

We are given two arrays of non-negative integers, a and b, both of length n. The allowed operation is to simultaneously decrement all positive elements of a by one.

codeforcescompetitive-programminggreedyimplementation
CF 1690A - Print a Pedestal (Codeforces logo?)

We are given a number of identical building blocks and must split them into three stacks representing a podium. Each stack corresponds to a rank: third place, second place, and first place.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1691C - Sum of Substrings

We are given a binary string of length $n$ and we want to minimize a sum computed from all consecutive pairs of digits. Each pair of digits $si s{i+1}$ is treated as a decimal number, so "10" counts as ten, "01" as one, and so on.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathstrings
CF 1691F - K-Set Tree

We are given an undirected tree with $n$ vertices. For every choice of a root $r$, the tree becomes rooted. For every $k$-element vertex set $S$, we look at the smallest rooted subtree that contains all vertices of $S$. A rooted subtree is not just any connected subgraph.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpmathtrees