brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1918E - ace5 and Task Order

We are given a hidden permutation of integers from 1 to $n$. The permutation is unknown, and our goal is to determine it.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquerimplementationinteractiveprobabilitiessortings
CF 1918F - Caterpillar on a Tree

The previous attempts failed for two reasons. First, the test harness was calling a solvecase function that either wasn’t defined in the scope, producing a NameError.

codeforcescompetitive-programmingdfs-and-similargraphsgreedyimplementationsortingstrees
CF 1918G - Permutation of Given

We are asked to construct an array of length $n$ containing non-zero integers such that if we replace each element by the sum of its neighbors, the resulting array is a permutation of the original array. For the endpoints, the "neighbor sum" is just the single adjacent element.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1918D - Blocking Elements

We are given an array of positive integers. Our goal is to "block" some elements in order to minimize a certain cost.

codeforcescompetitive-programmingbinary-searchdata-structuresdpimplementationtwo-pointers
CF 1918C - XOR-distance

The problem asks us to minimize the absolute difference between two numbers after each has been XOR-ed with a single number $x$ that we are allowed to choose.

codeforcescompetitive-programmingbitmasksgreedyimplementationmath
CF 1918B - Minimize Inversions

We are given two permutations a and b of the same length. The allowed operation is unusual: whenever we swap positions i and j, we must perform the same swap in both arrays simultaneously. This means we can never separate a[k] from b[k].

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationsortings
CF 1918A - Brick Wall

We are building a full $n times m$ rectangular grid using long thin bricks, where each brick is a $1 times k$ strip with $k ge 2$. Each brick must lie entirely either horizontally or vertically, and every cell of the grid must belong to exactly one brick.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1919F1 - Wine Factory (Easy Version)

Because every valve capacity is fixed at $10^{18}$, the valves never become a bottleneck. Any water that remains in tower $i$ after the wizard acts can always move completely into tower $i+1$. This changes the nature of the process dramatically.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1919H - Tree Diameter

We are asked to reconstruct an unknown tree with $n$ vertices and $n-1$ edges by interacting with a grader that allows two types of queries. The first query lets us assign arbitrary positive weights to the edges and returns the resulting diameter of the weighted tree.

codeforcescompetitive-programminginteractivetrees
Kvant Math Problem 1488

Let the squares in the sequence be

kvantmathematicsolympiad
CF 1919G - Tree LGM

We are asked to reconstruct a tree from a matrix of game outcomes. Each entry s[i][j] indicates whether the first player can force a win when the tree is rooted at vertex i and the coin starts at vertex j. A vertex can only move the coin to its children.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquergamestrees
CF 1919E - Counting Prefixes

We are asked to reverse-engineer a hidden array of size $n$ that contains only $1$ and $-1$. Instead of being given the array itself, we are given the sorted list of prefix sums of the array. The prefix sum at position $i$ is the sum of the first $i$ elements of the array.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpimplementationmath
CF 1919F2 - Wine Factory (Hard Version)

We are tasked with simulating a sequence of water towers, each containing an initial amount of water. In front of each tower stands a wizard who can convert a limited number of liters into wine.

codeforcescompetitive-programmingdata-structuresdpflowsgreedymatrices
CF 1919C - Grouping Increases

We are given an array and we must split it into two subsequences, call them $s$ and $t$, covering every element exactly once while preserving relative order inside each subsequence.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1919D - 01 Tree

We are given the distances from the root to the leaves of a binary tree, listed in DFS leaf order. Every internal vertex has exactly two children. One outgoing edge has weight 0 and the other has weight 1.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugreedysortingstrees
CF 1919A - Wallet Exchange

Alice and Bob each start with a wallet containing some number of coins. On every turn, the current player may either keep the wallets as they are or swap the two wallets. After that choice, they must remove exactly one coin from the wallet they currently hold.

codeforcescompetitive-programminggamesmath
CF 1919B - Plus-Minus Split

The string consists only of '+' and '-'. We can interpret each character as a number: '+' becomes +1, and '-' becomes -1. We are allowed to split this sequence into any number of contiguous non-empty pieces.

codeforcescompetitive-programminggreedy
CF 1920E - Counting Binary Strings

We are asked to count the number of binary strings such that the total number of substrings containing exactly one 1 equals a given number n, and no such substring has length exceeding a given maximum k. A substring is simply a consecutive portion of the string.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1920F2 - Smooth Sailing (Hard Version)

We are given a rectangular grid where some cells are islands, some are open ocean, and some are underwater volcanoes. Thomas wants to sail in loops that fully encircle the island without stepping onto it.

codeforcescompetitive-programmingbinary-searchdata-structuresdsugeometrygraphstrees
CF 1920F1 - Smooth Sailing (Easy Version)

We are given a 2D grid representing an island in the ocean. Each cell can be part of the island (), open ocean (.), or an underwater volcano (v). The island cells form a single contiguous shape not touching the grid edges.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardsugraphsshortest-paths
CF 1920D - Array Repetition

We start with an empty sequence and gradually build a very large array using two kinds of operations. The first operation appends a single value to the end, effectively extending the sequence by one element.

codeforcescompetitive-programmingbinary-searchbrute-forcedsuimplementationmath
CF 1920A - Satisfying Constraints

We are asked to determine how many integers satisfy a set of constraints. Each test case consists of multiple constraints on a single integer $k$. The constraints fall into three categories: $k$ must be at least $x$, $k$ must be at most $x$, and $k$ must not equal $x$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1920B - Summation Game

We are asked to simulate a two-step game played on an array of positive integers. The first player, Alice, can remove up to $k$ elements. She wants the final sum of the array to be as large as possible.

codeforcescompetitive-programminggamesgreedymathsortings
Kvant Math Problem 1486

Consider sequences $(a_1, a_2, a_3, \dots)$ satisfying the recurrence $a_k = a_{k-1} - a_{k-2}$ for $k \ge 3$, with terms chosen from the set $1, \frac12, \frac13, \dots$.

kvantmathematicsolympiad
CF 1920C - Partitioning the Array

This is a Type B problem, a proof of existence. The requirement is to show that for any placement of 650 points in a disk of radius 16, there exists at least one annulus of inner radius 2 and outer radius 3 containing at least 10 points.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1921G - Mischievous Shooter

We are given a grid of size $n times m$, each cell either containing a target represented by or empty represented by .. Shel has a shotgun that fires in one of four diagonal directions: right-down, left-down, left-up, or right-up.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpimplementation
Kvant Math Problem 1490

The statement as written can only be meaningful if the second triangle has side lengths $\sin x$, $\sin y$, $\sin z$.

kvantmathematicsolympiad
CF 1921E - Eat the Chip

We have a two-player game on a rectangular grid with height h and width w. Alice’s chip starts at (xa, ya) and can move down, down-left, or down-right. Bob’s chip starts at (xb, yb) and moves up, up-left, or up-right.

codeforcescompetitive-programmingbrute-forcegamesgreedymath
CF 1921D - Very Different Array

We have an array a of length n. Another array b contains m values, where m is at least n. We are allowed to choose exactly n elements from b, then arrange those chosen elements in any order to form a new array c.

codeforcescompetitive-programmingdata-structuresgreedysortingstwo-pointers
CF 1921F - Sum of Progression

We are given an array of integers and a set of queries. Each query specifies a starting index s, a step size d, and a count k. For a query, we must sum k elements of the array taken at indices s, s+d, s+2d, ...

codeforcescompetitive-programmingbrute-forcedata-structuresdpimplementationmath
CF 1921B - Arranging Cats

The task is to transform an initial arrangement of cats in boxes into a target arrangement using the fewest operations. Each box either contains a cat or is empty, and the initial state is given by a binary string s, while the target state is given by a binary string f.

codeforcescompetitive-programminggreedyimplementation
CF 1921A - Square

We are given the four vertices of a square on a 2D coordinate plane. The points are presented in arbitrary order, so we do not know which point is the bottom-left corner, top-right corner, and so on. The square has two special properties.

codeforcescompetitive-programminggreedymath
CF 1921C - Sending Messages

Stepan needs to send a series of messages at strictly increasing moments in time. His phone starts with a finite charge, loses a constant amount per unit of time while it is on, and consumes a fixed cost if he turns it off and then back on.

codeforcescompetitive-programminggreedymath
CF 1922F - Replace on Segment

We are given an array of integers, each between 1 and some maximum value $x$. We want to make every element equal using a special operation: select a contiguous subsegment of the array and a value $k$ not currently present in that subsegment, then replace every element in that…

codeforcescompetitive-programmingdpgraph-matchings
CF 1922A - Tricky Template

We are given three strings of equal length, and we need to construct a template string such that the first two strings match the template while the third one does not. Each position in the template can be either lowercase or uppercase.

codeforcescompetitive-programmingconstructive-algorithmsimplementationstrings
CF 1922E - Increasing Subsequences

We are asked to construct an array of integers with a very specific property: the total number of its increasing subsequences should equal a given integer $X$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedymath
CF 1922D - Berserk Monsters

We have a row of monsters, each with an attack value ai and a defense value di. Monocarp casts a berserk spell so that monsters attack their immediate neighbors each round.

codeforcescompetitive-programmingbrute-forcedata-structuresdsuimplementationmath
CF 1922B - Forming Triangles

We are given a set of sticks, each with a length that is a power of two. The input does not give the actual lengths directly but rather exponents $ai$ such that the stick's length is $2^{ai}$.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathsortings
CF 1922C - Closest Cities

We are given several cities placed along a one-dimensional number line. Each city has a coordinate, and the coordinates are strictly increasing. For each city, there exists a unique "closest" city, meaning that no two cities are equally close to it.

codeforcescompetitive-programminggreedyimplementationmath
CF 1923E - Count Paths

We are given a tree with n nodes, each colored with some integer between 1 and n. The task is to count the number of simple paths of length at least two such that the first and last nodes have the same color, and no intermediate node shares this color.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugraphstrees
CF 1923D - Slimes

We are given a row of slimes, each with a positive size. The slimes interact in a simple but constrained way: a slime can eat an adjacent slime if it is strictly larger, and upon eating, it grows by the eaten slime’s size.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1923F - Shrink-Reverse

We are given a binary string s of length n and a number k representing the maximum number of allowed operations. Each operation can either swap two characters of the string or remove all leading zeros and then reverse the string.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyhashingimplementationstring-suffix-structuresstrings
CF 1923A - Moving Chips

We are given a row of cells, each either containing a chip or empty. The goal is to move chips leftward into contiguous groups by repeatedly picking a chip and moving it into the closest empty cell to its left.

codeforcescompetitive-programminggreedyimplementation
CF 1923C - Find B

We are given an array c of positive integers and multiple queries asking whether certain subarrays of c are good.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1923B - Monsters Attack!

We have a line with our character at position 0 and monsters positioned at some coordinates $xi$, each with health $ai$. Every second, we can fire up to $k$ bullets, reducing the health of monsters we choose.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1924B - Space Harbour

We have a straight line with n points, each occupied by a ship. Some of these points already host harbours, each with an associated value. A ship at a point incurs a cost if it were to "move" to the next harbour to its right.

codeforcescompetitive-programmingdata-structuresimplementationmathsortings
CF 1924E - Paper Cutting Again

We are asked to model a stochastic process of repeatedly cutting a rectangular sheet of paper and discarding parts of it, and then compute the expected number of steps until its area falls below a threshold.

codeforcescompetitive-programmingcombinatoricsprobabilities
CF 1924F - Anti-Proxy Attendance

I can't write a correct editorial for Codeforces 1924F from the problem statement alone. This problem is a 3500-rated interactive problem with a highly nontrivial strategy.

codeforcescompetitive-programmingconstructive-algorithmsdpinteractiveternary-search
CF 1924C - Fractal Origami

We repeatedly perform the same fold on a square sheet. Every fold takes the current square, folds all four corners to its center, and produces a smaller square whose side length is multiplied by $1/sqrt2$.

codeforcescompetitive-programminggeometrymathmatrices
CF 1924D - Balanced Subsequences

We are working with strings made only from two types of parentheses, and we fix how many opening and closing brackets we must use. Each test case gives three numbers: how many '(' we must place, how many ')' we must place, and a target parameter k.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1924A - Did We Get Everything Covered?

We are given a string s and two integers n and k. Conceptually, we are asked to check if every string of length n that can be built using the first k letters of the alphabet appears somewhere as a subsequence in s.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedyshortest-pathsstrings
CF 1925D - Good Trip

We have a graph on n children. Only m pairs are marked as friends, and each friendship edge has an initial weight f. The teacher performs exactly k excursions. During each excursion, one unordered pair of children is selected uniformly at random from all possible pairs.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1925B - A Balanced Problemset?

We are asked to split an integer $x$ into exactly $n$ positive integers whose sum is $x$, in a way that maximizes the greatest common divisor of these integers. The input gives multiple test cases, each with values for $x$ and $n$.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1926F - Vlad and Avoiding X

We have a fixed $7 times 7$ board whose cells are either black or white. A configuration is considered bad if there exists a black cell whose four diagonal neighbors are also black. Such a pattern looks like an X centered at that cell.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpimplementation
CF 1926G - Vlad and Trouble at MIT

We are asked to separate music from sleeping students in a dormitory modeled as a tree. Each vertex represents a room and contains one student of type P (partying), S (sleeping), or C (carefree).

codeforcescompetitive-programmingdfs-and-similardpflowsgraphsgreedyimplementationtrees
CF 1926D - Vlad and Division

We are given a set of non-negative integers and asked to partition them into groups so that within each group, no two numbers share a 1-bit in the same position across the first 31 bits.

codeforcescompetitive-programmingbitmasksgreedy
CF 1926E - Vlad and an Odd Ordering

Vladislav has a deck of cards numbered from 1 to n. He wants to arrange them in a sequence with a peculiar rule. First, he takes all odd numbers and lays them out in increasing order. Then he takes all numbers that are twice an odd number and lays them out in increasing order.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdpimplementationmathnumber-theory
CF 1926C - Vlad and a Sum of Sum of Digits

For every test case, we are given a number n. Vlad writes all integers from 1 through n on the board. Then each integer is replaced by the sum of its decimal digits. The task is to compute $$sum{i=1}^{n} text{digitSum}(i)$$ where digitSum(i) is the sum of the digits of i.

codeforcescompetitive-programmingdpimplementation
Kvant Math Problem 1468

Place the isosceles triangle in coordinates as

kvantmathematicsolympiad
CF 1926A - Vlad and the Best of Five

The task is simple: for each string of length five consisting only of the letters A and B, determine which letter occurs more frequently. Each test case provides one such string, and we have multiple test cases to process.

codeforcescompetitive-programmingimplementation
CF 1926B - Vlad and Shapes

We are given a very small binary image, typically at most 10 by 10 cells. Every cell is either empty or filled. The grid contains exactly one connected geometric figure formed by ones, and that figure is guaranteed to be either a perfect square or a centered triangle (upright…

codeforcescompetitive-programminggeometryimplementation
CF 1927G - Paint Charges

We are given a one-dimensional strip of cells, where each cell contains a “paint charge” with a fixed radius. Activating a charge at position i does not just affect that cell, it paints a contiguous segment either extending left or extending right by exactly a[i] cells…

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 1927E - Klever Permutation

We need to build a permutation of the numbers from 1 to n such that every contiguous segment of length k has almost the same sum. More precisely, if we compute the sum of every window of length k, the largest and smallest of those sums may differ by at most 1.

codeforcescompetitive-programmingconstructive-algorithmsmathtwo-pointers
CF 1927F - Microcycle

We are asked to find a simple cycle in an undirected, weighted graph where the minimal edge in that cycle is as small as possible. The input is a series of graphs: each graph is described by the number of vertices, the number of edges, and a list of edges with weights.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedyimplementationsortingstrees
CF 1927D - Find the Different Ones!

The problem gives you an array of integers and a series of queries, each specifying a segment of that array. For each query, you are asked to find two positions within the segment such that the values at these positions are different.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpdsugreedytwo-pointers
CF 1927B - Following the String

We are given an array a that describes how a hidden string was built. For each position i, the value a[i] tells us how many times the character at position i has already appeared earlier in the string. If a[i] = 0, this character has never appeared before.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1927C - Choose the Different Ones!

We are given two arrays, a and b, and an even integer k. We need to pick exactly k/2 elements from each array such that the multiset of chosen elements contains all integers from 1 to k.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1927A - Make it White

We are given a small horizontal strip of cells, each of which can be black or white. Our goal is to make every cell white by repainting a single contiguous segment. The repainting operation turns every black cell in that segment white, and leaves white cells unchanged.

codeforcescompetitive-programminggreedystrings
CF 1928F - Digital Patterns

We are given a grid-like scarf made by interweaving horizontal threads with vertical threads. Each horizontal thread has a transparency coefficient, as does each vertical thread. When interwoven, the cell at row i and column j has transparency equal to a[i] + b[j].

codeforcescompetitive-programmingcombinatoricsdata-structuresimplementationmath
Kvant Math Problem 1482

Let

kvantmathematicsolympiad
CF 1928A - Rectangle Cutting

We are given a rectangle with sides $a$ and $b$, and we are asked whether it is possible to cut this rectangle along a line parallel to one of its sides into two smaller rectangles with integer dimensions, and then use these two pieces to form a rectangle that is different in…

codeforcescompetitive-programminggeometrymath
CF 1928D - Lonely Mountain Dungeons

We are asked to assemble an army from multiple races, each with a certain number of creatures. Each creature pair from the same race, if they are placed in different squads, contributes a fixed amount b to the army’s strength.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedymathternary-search
CF 1928E - Modular Sequence

We are building a sequence starting from a fixed initial value, and each next value is determined by choosing between two operations. One operation increases the current value by a fixed step size y, and the other replaces the current value by its remainder when divided by y.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpgraphsgreedymathnumber-theory
CF 1928B - Equalize

The problem gives us an array of integers and asks us to maximize the number of equal elements after adding a permutation of numbers from 1 to n to the array.

codeforcescompetitive-programmingbinary-searchgreedysortingstwo-pointers
CF 1928C - Physical Education Lesson

We are given a scenario in which students line up according to a repeating "first-$k$-th" pattern. The sequence starts with numbers $1$ to $k$, then reverses from $k-1$ down to $2$, and this whole block repeats every $2k-2$ positions.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
Kvant Math Problem 1474

Let the direction of the line used in the $i$-th projection be denoted by $\alpha_i$.

kvantmathematicsolympiad
CF 1929A - Sasha and the Beautiful Array

We are given an array of integers, and we may rearrange its elements in any order. The beauty of a particular arrangement is defined as the sum of differences between consecutive elements: $$(a2-a1)+(a3-a2)+cdots+(an-a{n-1})$$ Our task is to choose the ordering that produces…

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1930I - Counting Is Fun

We are given a binary template string $p$ of length $n$. We are asked to count how many binary strings $q$ of the same length are valid under a global consistency rule that is defined locally in a slightly indirect way.

codeforcescompetitive-programmingcombinatorics
CF 1930D2 - Sum over all Substrings (Hard Version)

For every binary pattern $p$, we define $f(p)$ as the minimum number of 1s in another binary string $q$ of the same length such that every position of $p$ can "justify" its value by looking at some interval of $q$ containing that position.

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpdsugreedyimplementationstrings
CF 1930E - 2..3...4.... Wonderful! Wonderful!

We start with the array $$[1,2,3,dots,n].$$ A value $k$ is fixed for the whole process. In one operation we choose a subsequence of length $2k+1$. Among those chosen elements, we delete the first $k$ and the last $k$, keeping only the middle one.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1930A - Maximise The Score

We are given a list of 2n positive integers, and we need to perform exactly n moves. Each move consists of picking two numbers from the list, adding the smaller of the two to our score, and removing both numbers from the list.

codeforcescompetitive-programminggreedysortings
CF 1931G - One-Dimensional Puzzle

We are asked to count the number of ways to assemble a one-dimensional puzzle using four distinct types of tiles. Each tile has connections on the left and right, which can be a protrusion or a recess.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1931D - Divisible Pairs

We are given an array of integers and two numbers, $x$ and $y$. A pair of indices $(i, j)$ with $i < j$ is considered "beautiful" if the sum of the two elements $ai + aj$ is divisible by $x$ and the difference $ai - aj$ is divisible by $y$.

codeforcescompetitive-programmingcombinatoricsmathnumber-theory
CF 1931F - Chat Screenshots

We are given a chat with n participants, each identified by a unique number from 1 to n. The chat displays participants in a list ordered by activity, but each participant always sees themselves at the top of their own list.

codeforcescompetitive-programmingcombinatoricsdfs-and-similargraphs
CF 1931E - Anna and the Valentine's Day Gift

The game begins with a list of integers. Anna moves first by reversing the digits of any number, which can increase or decrease its value depending on the digits. Sasha moves second by concatenating any two numbers, reducing the list size by one.

codeforcescompetitive-programminggamesgreedymathsortings
CF 1931C - Make Equal Again

We are given an array of integers and we want to make all elements equal. We are allowed to perform at most one operation, which consists of picking a contiguous subarray and setting all its elements to some value.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1931A - Recovering a Small String

We are given a single integer that represents the sum of three hidden lowercase letters. Each letter contributes its position in the alphabet, so a contributes 1, b contributes 2, and so on up to z contributing 26.

codeforcescompetitive-programmingbrute-forcestrings
CF 1931B - Make Equal

We are given several independent scenarios. In each scenario there is a line of containers, each holding some amount of water. We are allowed to move water, but only from a container on the left to a container on the right.

codeforcescompetitive-programminggreedy
CF 1932G - Moving Platforms

We are given a graph of platforms, where each platform has a level between 0 and H-1. Moving from one platform to another is only allowed along a passage and only if the levels match at that moment.

codeforcescompetitive-programminggraphsmathnumber-theoryshortest-paths
CF 1932F - Feed Cats

We are given a timeline of n steps, and m cats, each defined by the interval [li, ri] during which it appears. At each step, we can feed all cats present, but feeding a cat more than once will cause a loss.

codeforcescompetitive-programmingdata-structuresdpsortings
CF 1932D - Card Game

We are asked to reconstruct rounds of a two-player card game from a shuffled discard pile. The game uses a 32-card deck with four suits (clubs, diamonds, hearts, spades) and ranks from 2 to 9. One suit is declared trump.

codeforcescompetitive-programminggreedyimplementation
CF 1932C - LR-remainders

We are given an array that shrinks from both ends based on a sequence of instructions. At every step, before we remove anything, we must compute the product of all remaining elements modulo a fixed number $m$.

codeforcescompetitive-programmingbrute-forcedata-structuresimplementationmathtwo-pointers
CF 1932E - Final Countdown

We have a mechanical countdown timer that displays a number with $n$ digits. Each second, the countdown decrements by one. The catch is that the decrement is not instantaneous across all digits.

codeforcescompetitive-programmingimplementationmathnumber-theory
CF 1932B - Chaya Calendar

The problem describes a sequence of events, called signs, that occur periodically. Each sign i has a period ai, meaning it happens every ai years: in years ai, 2 ai, 3 ai, and so on. The tribe is waiting for the apocalypse, which only happens when the signs occur sequentially.

codeforcescompetitive-programmingnumber-theory
CF 1932A - Thorns and Coins

We are given a one-dimensional path made of cells. Each cell is either empty, contains a coin, or is blocked by thorns. We start at the first cell, which is guaranteed to be empty, and we want to move to the right as far as possible while collecting coins.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1933G - Turtle Magic: Royal Turtle Shell Pattern

We are given an $n times m$ grid representing a fortune cookie box. Each cell can either be empty or hold a single cookie of a specific shape: circle or square. Initially, all cells are empty. A sequence of $q$ operations fills certain cells with a specified shape.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsconstructive-algorithmsdfs-and-similarmath
CF 1933F - Turtle Mission: Robot and the Earthquake

The problem describes a robot navigating a toroidal grid, where the rows wrap cyclically. Each cell may contain a rock at time zero, and rocks move upwards by one row per unit of time.

codeforcescompetitive-programmingdfs-and-similardpgraphsshortest-paths
CF 1933E - Turtle vs. Rabbit Race: Optimal Trainings

We are asked to model Isaac's training across multiple running tracks. Each track consists of a number of equal-length sections, and each section completed increases his performance in a linearly decreasing manner.

codeforcescompetitive-programmingbinary-searchimplementationmathternary-search
CF 1933D - Turtle Tenacity: Continual Mods

We are given an array of integers, and we need to decide if we can reorder the array such that when we apply modulo operations consecutively from left to right, the final result is not zero.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theorysortings
CF 1933A - Turtle Puzzle: Rearrange and Negate

Take the first test case: Tree structure: - If we remove vertex 1, the neighbors are [3,4]. - The previous solution connects 3-4 for cost 1, which is correct. - If we remove vertex 4, neighbors are [1,5].

codeforcescompetitive-programminggreedymathsortings