brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1443A - Kids Seating

We are asked to seat a group of $n$ children on a line of chairs numbered from $1$ to $4n$ such that no two children can "indulge." Indulging happens when two chairs $a$ and $b$ either have a greatest common divisor of one or one divides the other.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1443B - Saving the City

We are given a city represented as a line of buildings, each of which may or may not have a mine. The city map is a string of zeros and ones, where "1" indicates a mine and "0" indicates a safe building.

codeforcescompetitive-programmingdpgreedymathsortings
CF 1444A - Division

Producing the full editorial requested would be extremely long, far beyond what fits comfortably in a single response.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1444E - Finding the Vertex

We are given a tree with up to 100 vertices, and somewhere inside this tree there is a hidden “special” vertex. We do not know which one it is.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpinteractivetrees
CF 1444C - Team-Building

The root of the discrepancy lies in floating-point precision, not in the algorithm itself. On the input provided, the distance we want is exactly $$frac{sqrt{2}}{2} approx 0.7071067811865476$$ However, the expected output in the sample is 0.707106780737, which is slightly lower.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphs
CF 1444D - Rectangular Polyline

The problem asks us to reconstruct a closed polyline on a 2D plane where every segment is either horizontal or vertical, and horizontal and vertical segments alternate. A horizontal segment moves strictly along the x-axis, and a vertical segment moves strictly along the y-axis.

codeforcescompetitive-programmingconstructive-algorithmsdpgeometry
CF 1444B - Divide and Sum

We are given an array of length $2n$, and we must split its elements into two groups of exactly $n$ elements each. Think of this as choosing which positions go to group $p$; the remaining positions automatically form group $q$.

codeforcescompetitive-programmingcombinatoricsmathsortings
CF 1445A - Array Rearrangment

We are given two lists of numbers of equal length, and we are allowed to reorder only the second list. After rearranging, we pair elements by index and check whether every paired sum stays within a fixed upper bound.

codeforcescompetitive-programminggreedysortings
CF 1445B - Elimination

We are asked to compute the smallest possible cutoff total score for an olympiad elimination stage. Each participant competes in two contests, and the jury only remembers partial information: the 100-th place score in each contest and a lower bound on the other contest's score…

codeforcescompetitive-programminggreedymath
CF 1446F - Line Distance

We are given a set of points on the plane and asked to consider the line formed by every pair of points. For each line, we measure its perpendicular distance to the origin. The goal is to find the k-th smallest of all these distances.

codeforcescompetitive-programmingbinary-searchdata-structuresgeometry
CF 1446C - Xor Tree

Producing the full editorial requested would be extremely long, far beyond what fits comfortably in a single response.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdivide-and-conquerdptrees
CF 1446E - Long Recovery

The system describes an infinite triangular grid where every cell has exactly three neighbors. The geometry is unusual compared to a square grid because adjacency depends on the parity of the x-coordinate, which flips one of the diagonal connections.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similar
CF 1446D2 - Frequency Problem (Hard Version)

We are given an array of integers of length n. Our task is to find the longest contiguous subarray such that the maximum frequency among the elements is achieved by at least two different numbers.

codeforcescompetitive-programmingdata-structuresgreedytwo-pointers
CF 1446D1 - Frequency Problem (Easy Version)

We are given an array of integers and asked to find the longest contiguous subarray where the most frequent value is tied, meaning there is no single dominant element.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1446B - Catching Cheaters

We have two essays represented as strings, and we want to find the most suspicious overlap between them. The overlap is measured using a similarity score defined as four times the length of the longest common subsequence of two substrings, minus the sum of their lengths.

codeforcescompetitive-programmingdpstrings
CF 1446A - Knapsack

We are given several independent test cases. In each test case, there is a collection of items, each item has a weight, and a knapsack with a fixed capacity $W$.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 1447B - Numbers Box

We are given a circle of points, each point representing a spool that must be paired with exactly one other spool using a straight chord. Every spool has a color, black or white, and some positions are initially uncolored and can be assigned either color.

codeforcescompetitive-programminggreedymath
CF 1447A - Add Candies

We start with a very structured array: the i-th bag contains exactly i candies. So the initial state is simply an arithmetic progression like 1, 2, 3, ..., n.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450H2 - Multithreading (Hard Version)

We are given a circle of points, each point representing a spool that must be paired with exactly one other spool using a straight chord. Every spool has a color, black or white, and some positions are initially uncolored and can be assigned either color.

codeforcescompetitive-programmingcombinatoricsimplementationmath
CF 1450B - Balls of Steel

We are given several steel balls placed at distinct coordinates on a plane. A charged ball acts like a magnet with radius measured in Manhattan distance.

codeforcescompetitive-programmingbrute-forcegeometrygreedy
CF 1450H1 - Multithreading (Easy Version)

We are working with points placed on a circle, where each position can be colored black, white, or left undecided. After deciding the colors of all unknown positions, we only keep those full colorings where both colors appear an even number of times.

codeforcescompetitive-programmingcombinatoricsfftmath
CF 1450F - The Struggling Contestant

We are given several independent test cases. In each one, we have a sequence of problem tags, and we want to arrange all indices of this sequence into a permutation, meaning we reorder which problem we solve at each step. Two constraints shape this ordering.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1450G - Communism

We are given a row of n workers, each with a job category represented by a lowercase English letter. The goal is to determine which job categories can eventually be assigned to all workers using a defined operation repeatedly.

codeforcescompetitive-programmingbitmasksdptrees
CF 1450E - Capitalism

We are given a connected undirected graph where each vertex represents a person and each edge represents a friendship.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsshortest-paths
Kvant Math Problem 150

Consider first the simplest cases to gain intuition.

kvantmathematicsolympiad
CF 1450C1 - Errich-Tac-Toe (Easy Version)

We are given a square board where each cell may be empty or contain an X. The goal is to modify the board so that no row or column contains three identical non-empty symbols in a consecutive block.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450D - Rating Compression

We are given an array of integers representing the rating graph of a user on a competitive programming platform. For each integer $k$ from 1 to $n$, we are asked to consider the "k-compression" of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementationtwo-pointers
CF 1450C2 - Errich-Tac-Toe (Hard Version)

We are given a square board filled with three possible symbols: empty cells, X tokens, and O tokens. The only way a configuration becomes “bad” is when three identical tokens appear consecutively in a straight line, either horizontally or vertically.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1450A - Avoid Trygub

We are given a string a consisting of lowercase English letters. The task is to reorder its characters into a string b such that the string "trygub" does not appear as a subsequence in b.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1451F - Nullify The Matrix

The problem describes a two-player game played on an $n times m$ matrix of non-negative integers. Players alternate moves, starting with Ashish.

codeforcescompetitive-programmingconstructive-algorithmsgames
CF 1451E2 - Bitwise Queries (Hard Version)

The reported ZeroDivisionError is a symptom, not the root cause. Let's trace the failing input against the code that was previously suggested: The code interprets: - t = 5 - Test 1: a = [2, 4], so n = 2 - Test 2: a = [3, 1], so n = 2 - Test 3: a = [3, 4], so n = 2 - Test 4: a…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1451E1 - Bitwise Queries (Easy Version)

We are given a hidden array of size $n$, where $n$ is a power of two. Each element in the array is an integer in the range $[0, n-1]$. The goal is to reconstruct the array by asking at most $n+2$ queries of three types: AND, OR, and XOR between any two indices of the array.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1451B - Non-Substring Subsequence

We are given a binary string and multiple range queries. Each query selects a contiguous substring, and we must decide whether this substring can appear as a subsequence somewhere in the same string under a constraint: the subsequence must not be taken as a contiguous block…

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 1451A - Subtract or Divide

The reported ZeroDivisionError is a symptom, not the root cause. Let's trace the failing input against the code that was previously suggested: The code interprets: - t = 5 - Test 1: a = [2, 4], so n = 2 - Test 2: a = [3, 1], so n = 2 - Test 3: a = [3, 4], so n = 2 - Test 4: a…

codeforcescompetitive-programminggreedymath
CF 1451D - Circle Game

We are given a circle centered at the origin with radius $d$. Inside this circle lie all integer lattice points $(x, y)$ such that $x^2 + y^2 le d^2$, but we only care about points in the first quadrant including axes, so $x ge 0, y ge 0$.

codeforcescompetitive-programminggamesgeometrymath
CF 1451C - String Equality

We are given two strings, a and b, of equal length n, along with an integer k. The goal is to determine whether we can transform a into b using two types of operations. The first operation allows swapping any adjacent characters in a.

codeforcescompetitive-programmingdpgreedyhashingimplementationstrings
CF 1452G - Game On Tree

I see exactly what went wrong in the previous implementation. The problem is subtle: the “all equal” case [1, 1, 1] fails because the formula incorrectly tries to round the sum to the next multiple of n-1 even when the current sum is already enough to satisfy the maxa…

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
Kvant Math Problem 1485

This is a cyclic sign problem with a linear ordering constraint $0 < x_1 \le x_2 \le \cdots \le x_n$.

kvantmathematicsolympiad
CF 1452C - Two Brackets

Ah, now I see exactly why the previous solution produced wrong output. The earlier code assumes that every digit exists on the board and adds a maximal area even when the digit does not exist at all, or when it occurs in multiple rows and columns without considering the…

codeforcescompetitive-programminggreedy
CF 1452F - Divide Powers

We are given a collection of numbers where every element is a power of two. Instead of listing them explicitly, the input tells us how many copies we have of each value $2^i$. Think of it as a multiset where level $i$ contributes $cnti$ identical tokens, each worth $2^i$.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1452B - Toy Blocks

We are given a set of boxes, each containing a certain number of toy blocks. The game consists of a child choosing a single box and attempting to redistribute all its blocks evenly across the other boxes.

codeforcescompetitive-programmingbinary-searchgreedymathsortings
CF 1452E - Two Editorials

We are given a problemset of n problems and m participants. Each participant is interested in a specific contiguous range of problems, defined by [li, ri]. Two authors are going to present tutorials, each covering exactly k consecutive problems.

codeforcescompetitive-programmingbrute-forcedpgreedysortingstwo-pointers
CF 1452D - Radio Towers

We have a line of $n + 2$ towns, numbered from $0$ to $n + 1$, positioned at consecutive integer coordinates. Towns $1$ through $n$ may independently receive a radio tower, each with probability $frac{1}{2}$.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1452A - Robot Program

We have a robot standing at the origin of an infinite 2D grid, and we need to guide it to a target cell with coordinates $(x, y)$. The robot can move north, east, south, west, or stay in place, but it cannot repeat the same command consecutively.

codeforcescompetitive-programmingmath
CF 1453B - Suffix Operations

We are given an array of integers and a machine that can increment or decrement all elements of a suffix of the array by 1. A suffix is any contiguous segment that includes the last element. Our goal is to make all elements equal using as few operations as possible.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1453F - Even Harder

We can view the game as a directed graph laid out on a line of positions from 1 to n. From position i, the player may jump forward to any position j such that j is strictly greater than i and at most i + a[i].

codeforcescompetitive-programmingdp
CF 1453C - Triangles

We are given a square board of size n × n where each cell contains a digit between 0 and 9. For each digit d, we want to find a triangle whose vertices are the centers of cells containing d, with at least one side parallel to the board edges, such that the area of this…

codeforcescompetitive-programminggreedyimplementation
CF 1453E - Dog Snacks

We are given a tree with $n$ vertices, each vertex containing a snack. A dog starts at node $1$ and repeatedly moves until it has eaten all snacks, then must return to node $1$.

codeforcescompetitive-programmingbinary-searchdfs-and-similardpgreedytrees
CF 1453D - Checkpoints

The problem asks us to design a sequence of game stages and checkpoints so that a player with a 50% chance of beating any stage has an exact expected number of tries over the whole game. Every stage may or may not have a checkpoint, and the first stage always has one.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathprobabilities
CF 1453A - Cancel the Trains

We are asked to manage a train system on a 100×100 grid. Trains can move either vertically from the bottom to the top or horizontally from the left to the right.

codeforcescompetitive-programmingimplementation
CF 1454C - Sequence Transformation

We are given a sequence of integers, and the goal is to make all elements equal by repeatedly removing contiguous segments that do not contain a chosen value $x$. The choice of $x$ is critical because once we pick it, it cannot change.

codeforcescompetitive-programminggreedyimplementation
CF 1454A - Special Permutation

The task is to construct a permutation of length (n 1) such that no element occupies its original position. In other words, for a permutation (p) of size (n), we require that (pi ne i) for every index (i).

codeforcescompetitive-programmingconstructive-algorithmsprobabilities
CF 1454F - Array Partition

We are given an array and we want to cut it into three consecutive non-empty segments. Let us call them the left part, the middle part, and the right part.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedytwo-pointers
CF 1454E - Number of Simple Paths

We are given a connected undirected graph where the number of edges equals the number of vertices. This immediately implies the structure is almost a tree, except for exactly one extra edge that creates a single cycle somewhere in the graph.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphstrees
CF 1454D - Number into Sequence

We are given a single integer $n$, and we want to break it into a sequence of integers greater than 1. These integers are not arbitrary factors, but are constrained by a divisibility chain: each next number must be divisible by the previous one.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
Kvant Math Problem 1472

The table is a cyclic Latin square, so the entry in row $i$ and column $j$ equals $j-i+1 \pmod n$ in the set ${1,2,\dots,n}$.

kvantmathematicsolympiad
CF 1454B - Unique Bid Auction

We are asked to determine the winner of a simplified "Unique Bid Auction." Each participant chooses a number, and the winner is the participant who picked a number that no one else picked, and that is the smallest among all such unique numbers.

codeforcescompetitive-programmingimplementation
CF 1455D - Sequence and Swaps

The error you are seeing: is not about the algorithm. Python is telling you that there is no function called solve defined in your code. This is a purely structural/typo issue: you cannot call a function that has not been defined yet. The root causes usually are: 1.

codeforcescompetitive-programmingdpgreedysortings
CF 1455G - Forbidden Value

The task is to simulate a simplified programming language where a single variable x can be assigned values through set instructions.

codeforcescompetitive-programmingdata-structuresdp
CF 1455F - String and Operations

We are given a string s of length n whose characters are restricted to the first k lowercase letters of the Latin alphabet. For each character in s, we can perform one operation, and each operation must be applied exactly once in the order of the original positions.

codeforcescompetitive-programmingdpgreedy
CF 1455E - Four Points

We are given four distinct points on a 2D integer grid and can move any point by one unit in either the x or y direction per move. The goal is to transform these points into the vertices of an axis-aligned square using the minimum total number of moves.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsflowsgeometrygreedyimplementationmathternary-search
CF 1455A - Strange Functions

The proposed solution correctly identifies the probability requested: the probability that a single subtract-and-shift cycle produces an odd value $w$ in the range $[2^n,2^{n+1})$ while the other argument remains in $Omega$.

codeforcescompetitive-programmingmathnumber-theory
CF 1455C - Ping-pong

We are simulating a ping-pong game where two players, Alice and Bob, have finite stamina. Each action, whether serving or returning, costs 1 stamina. Alice always serves first.

codeforcescompetitive-programmingconstructive-algorithmsgamesmath
CF 1455B - Jumps

We start at position 0 on a number line and want to reach a positive integer x. We perform jumps one by one, and the k-th jump has a special rule: it either moves us forward by k units or backward by 1 unit.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1456E - XOR-ranges

We are asked to construct an array of length $n$ such that each element lies within a given segment $[li, ri]$ and the sum of costs of consecutive XOR differences is minimized. Each number $x$ has a cost defined by its set bits: the $i$-th bit contributes $ci$ to the cost.

codeforcescompetitive-programmingdpgreedy
CF 1458F - Range Diameter Sum

The failure here is not algorithmic at all. The GCD reduction logic for this problem is correct and already known to be optimal. The actual bug is purely in the execution wrapper and not in the solution idea.

codeforcescompetitive-programmingdata-structurestrees
Kvant Math Problem 1471

The skier’s route can be represented as a cyclic sequence of length $2n$, denoted $v_1, v_2, \dots, v_{2n}$ with $v_{2n+1} = v_1$, in which each of the $n$ villages appears exactly twice.

kvantmathematicsolympiad
CF 1458E - Nim Shortcuts

We are asked to analyze a variation of the two-heap Nim game. In classic Nim with two heaps, each player can take any positive number of stones from either heap. The player who cannot make a move loses.

codeforcescompetitive-programmingdata-structuresgames
CF 1458C - Latin Square

We start with an (n times n) Latin square. Every row is a permutation of (1 ldots n), and every column is also a permutation of (1 ldots n). A sequence of operations modifies the matrix. Four operations perform cyclic shifts of rows or columns.

codeforcescompetitive-programmingmathmatrices
CF 1458A - Row GCD

The problem presents us with two sequences of integers: the first sequence a contains n elements, and the second sequence b contains m elements.

codeforcescompetitive-programmingmathnumber-theory
CF 1458D - Flip and Reverse

We are given a binary string consisting of 0's and 1's, and we are allowed to perform a specific operation any number of times.

codeforcescompetitive-programmingdata-structuresgraphsgreedy
CF 1458B - Glass Half Spilled

We have up to 100 glasses. Glass i can hold ai units of water and currently contains bi units. We are allowed to move water between glasses. The catch is that every transfer loses half of the transferred amount.

codeforcescompetitive-programmingdp
CF 1459B - Move and Turn

The robot starts at (0, 0) and makes exactly n moves. Every move has length 1. The first move may be in any cardinal direction. After that, the robot is forced to alternate between vertical and horizontal movement.

codeforcescompetitive-programmingdpmath
CF 1459A - Red-Blue Shuffle

We are given a set of n cards, each with two digits: one red and one blue. After shuffling all the cards randomly, we read the red digits from left to right to form a number R and the blue digits similarly to form B.

codeforcescompetitive-programmingmathprobabilities
CF 1461C - Random Events

We are given an initial permutation and a sequence of probabilistic operations. Each operation focuses on a prefix of the permutation and, independently, sorts that prefix with a given probability.

codeforcescompetitive-programmingdpmathprobabilities
CF 1461E - Water Level

We are asked to manage a water cooler over a number of days. The cooler starts with k liters of water, and every day x liters are consumed by coworkers. At the beginning of each day, John can add exactly y liters of water if doing so does not exceed the maximum limit r.

codeforcescompetitive-programmingbrute-forcegraphsgreedyimplementationmath
CF 1461F - Mathematical Expression

We are given a sequence of digits, each between 0 and 9, and a set of allowed operators, which can be any combination of addition, subtraction, and multiplication.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1461D - Divide and Summarize

We start with an array and repeatedly apply a very specific splitting rule. For any current array, compute $$mid = leftlfloor frac{min + max}{2} rightrfloor$$ All elements whose value is at most mid form one group, and all elements whose value is greater than mid form the other.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquerimplementationsortings
Kvant Math Problem 14

Assume the convex polyhedron admits an inscribed sphere of radius $r$ with center $O$.

kvantmathematicsolympiad
CF 1461B - Find the Spruce

We are given a grid made of two types of cells: filled cells marked with and empty cells marked with .. Inside this grid, we want to count how many valid “spruce shapes” exist.

codeforcescompetitive-programmingbrute-forcedpimplementation
CF 1461A - String Generation

We are asked to construct a string of length n using only the characters 'a', 'b', and 'c', while ensuring that no palindromic substring exceeds length k. A substring is any contiguous segment of the string, and a palindrome reads the same forwards and backwards.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1462E1 - Close Tuples (easy version)

We are given an array of integers where each element is between 1 and n, and we are asked to count the number of triples (i, j, z) such that the maximum value in the triple differs from the minimum by at most 2.

codeforcescompetitive-programmingbinary-searchcombinatoricsmathsortingstwo-pointers
CF 1462F - The Treasure of The Segments

We are given several independent test cases. In each test case, there is a collection of closed intervals on a number line. From this collection we want to keep as many intervals as possible, but only under a structural constraint.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedy
CF 1462E2 - Close Tuples (hard version)

We are asked to count specific subsets of an array where the elements are "close" to each other. More precisely, we have an array of integers a of length n, and we want the number of size-m tuples such that the difference between the largest and smallest element in the tuple…

codeforcescompetitive-programmingbinary-searchcombinatoricsimplementationmathsortingstwo-pointers
CF 1462C - Unique Number

We are given a target sum of digits, and we must construct the smallest positive integer whose digits are all different and whose digits add up exactly to that target. The output is not just any valid number, but the smallest one in standard decimal ordering.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1462D - Add to Neighbour and Remove

We are given an array of integers, and the goal is to make all elements equal using a specific operation any number of times. The operation allows picking an element and adding its value to one of its neighbors, then removing that element.

codeforcescompetitive-programminggreedymathnumber-theory
Kvant Math Problem 1279

Consider a configuration of $n$ non-overlapping unit squares on the plane with sides parallel to the axes such that any two squares can be intersected by a line parallel to the $x$-axis or the $y$-axi…

kvantmathematicsolympiad
CF 1462B - Last Year's Substring

The problem presents a string of digits and asks whether it can be transformed into the string "2020" using at most one contiguous deletion. Polycarp may remove zero or more consecutive characters anywhere in the string.

codeforcescompetitive-programmingdpimplementationstrings
CF 1462A - Favorite Sequence

Polycarp has a favorite sequence of integers, but we do not see it directly. Instead, we see the result of a special writing process he performs.

codeforcescompetitive-programmingimplementationtwo-pointers
CF 1463D - Pairs

We are given the integers from $1$ to $2n$, and we need to form them into $n$ pairs. Once the pairs are formed, we are allowed to select $x$ of them and take the minimum elements from those pairs, while from the remaining $n - x$ pairs we take the maximum elements.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedytwo-pointers
CF 1463F - Max Correct Set

We are asked to find the largest subset of the integers from 1 to $n$ such that no two numbers in the subset differ by exactly $x$ or exactly $y$. Conceptually, think of the numbers as positions on a line.

codeforcescompetitive-programmingbitmasksdpmath
CF 1463E - Plan of Lectures

We have a teacher, Ivan, who needs to schedule lectures on n different topics. Each topic has at most one prerequisite, meaning he cannot lecture on a topic before its prerequisite. One topic has no prerequisite.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsugraphsimplementationsortingstrees
CF 1463C - Busy Robot

A single robot moves on a straight line starting from position zero. You send it a sequence of commands, each specifying a time and a target position. When a command arrives, the robot immediately commits to moving toward that target at unit speed.

codeforcescompetitive-programmingimplementation
CF 1463B - Find The Array

We are given an array of integers $a = [a1, a2, dots, an]$, each between 1 and $10^9$, and we need to construct another array $b$ of the same length. This new array must satisfy three properties. First, each element $bi$ must also lie between 1 and $10^9$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 1463A - Dungeon

We have three monsters with health values a, b, and c. A normal cannon shot deals 1 damage to exactly one living monster. Every seventh shot is special. Instead of targeting a single monster, it deals 1 damage to every monster that is still alive at that moment.

codeforcescompetitive-programmingbinary-searchmath
CF 1464F - My Beautiful Madness

We maintain a multiset of paths on a tree. Paths can be inserted and deleted dynamically. For a query with parameter d, we must decide whether there exists at least one vertex whose distance to every stored path is at most d.

codeforcescompetitive-programmingdata-structurestrees
CF 1466H - Finding satisfactory solutions

We are given n agents and a permutation of n items representing an optimal assignment, where agent i receives item A[i]. Each agent initially owns a unique item corresponding to their index. A preference profile assigns a ranking of all items for each agent.

codeforcescompetitive-programmingcombinatoricsdpgraphsgreedymath
CF 1466I - The Riddle of the Sphinx

We are given a hidden array of length n. Each element is an integer in the range [0, 2^b - 1]. We never see the values directly. Instead, we can repeatedly choose an index i and a number y, and ask whether a[i] y.

codeforcescompetitive-programmingbinary-searchdata-structuresinteractive
CF 1466G - Song of the Sirens

We start with a short string $s0$. Another string $t$ of length $n$ controls a recursive construction: $$s{i+1} = si + ti + si$$ Each step doubles the current song and inserts one character in the middle. Queries ask for a level $k$ and a pattern $w$.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerhashingmathstring-suffix-structuresstrings
CF 1466F - Euclid's nightmare

We are given a collection of binary vectors of length $m$, where each vector contains at most two positions set to 1. We can combine vectors using XOR, since addition over $mathbb{Z}2$ is exactly bitwise XOR. From all possible XORs of subsets of these vectors, we form a set $T$.

codeforcescompetitive-programmingbitmasksdfs-and-similardsugraphsgreedymathsortings