brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1873B - Good Kid

We are given a small collection of digits, and we are allowed to increase exactly one of them by one unit. After this single modification, we compute the product of all digits and want to maximize it.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1873C - Target Practice

We are given a $10 times 10$ grid representing a target with five concentric scoring rings. Each cell of the grid either contains an arrow, denoted by X, or is empty, denoted by ..

codeforcescompetitive-programmingimplementationmath
CF 1873A - Short Sort

We are given three distinct cards labeled a, b, and c, arranged in some order. Our goal is to determine whether, using at most one swap of two cards, we can transform the row into the ordered sequence abc.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1874G - Jellyfish and Inscryption

We are asked to navigate a directed acyclic graph (DAG) from vertex 1 to vertex n, collecting cards and props along the way, and then maximize our total “power” at the end. Cards have both HP and damage, and their power is the product of the two.

codeforcescompetitive-programmingdp
CF 1874F - Jellyfish and OEIS

We are asked to count permutations of numbers from 1 to n that avoid certain ordered subarrays. More concretely, for each index l, we are given a number ml, and any contiguous segment starting at l and ending at r ≤ ml must not be a consecutive permutation of [l, l+1, ..., r].

codeforcescompetitive-programmingdp
CF 1874D - Jellyfish and Miku

We have a simple linear chain of cities numbered from 0 to n, connected sequentially by n roads. Each road has a "beauty" value, which determines the probability that Jellyfish will traverse it if she stands at one of its endpoints.

codeforcescompetitive-programmingdivide-and-conquerdpmathprobabilities
CF 1874E - Jellyfish and Hack

We are asked to analyze a variant of quicksort where the first element is always chosen as the pivot. For any array, the "time" the function takes is defined recursively as the size of the array plus the time taken by the recursive calls on elements smaller and larger than the…

codeforcescompetitive-programmingdpmath
CF 1874B - Jellyfish and Math

We are asked to transform a pair of non-negative integers (x, y) from an initial state (a, b) to a target state (c, d) using a small set of bitwise operations. The operations available are x := x & y, x := x The constraints are significant.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpgraphsshortest-paths
CF 1874A - Jellyfish and Game

We have two players, Jellyfish and Gellyfish, each with a collection of green apples. Jellyfish has n apples with values stored in array a, and Gellyfish has m apples with values stored in array b. They play a game for k rounds.

codeforcescompetitive-programmingbrute-forcegamesgreedyimplementation
CF 1874C - Jellyfish and EVA

We are given a directed acyclic graph in a very specific form: every edge goes from a smaller numbered city to a larger numbered city. This means the graph is already topologically sorted by vertex index. We start at city 1 and want to reach city n.

codeforcescompetitive-programmingdpgraphsgreedymathprobabilities
Kvant Math Problem 1526

The condition $abc=1$ suggests eliminating one variable from denominators by rewriting powers of $a,b,c$ in terms of the other two variables.

kvantmathematicsolympiad
CF 1876G - Clubstep

Chaneka is trying to master a challenging video game level divided into n sequential parts. She starts with some familiarity value for each part, given as an array a of size n.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedytrees
CF 1876F - Indefinite Clownfish

We are asked to pick exactly k clownfish from a sequence of n available fish, each with a given size. Each fish can be assigned either a female or male gender at the time of selection, but the genders follow strict sequence rules.

codeforcescompetitive-programmingbinary-searchgraphs
CF 1876E - Ball-Stackable

We are given a tree where every edge is either already directed or still undirected. The task is to decide two things for the undirected edges: their directions and a color assignment for every edge. Directed edges already come with a fixed direction but still need a color.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdptrees
CF 1876D - Lexichromatography

We are given an array of integers, and our task is to assign each element one of two colors, blue or red. The goal is to count all colorings that satisfy two conditions.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardsugraphstwo-pointers
CF 1876C - Autosynthesis

We are given an array of positive integers a of length n. The task is to perform a sequence of "circle" operations on elements of a. Each operation selects an element by its index and "circles" it, and we can circle the same element multiple times.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedysortings
CF 1876A - Helmets in Night Light

We are asked to distribute an announcement among $n$ residents at minimum cost. Pak Chanek can notify any resident directly at cost $p$, and each resident who receives the announcement can forward it to a limited number of other residents $ai$, paying $bi$ per share.

codeforcescompetitive-programminggreedysortings
CF 1876B - Effects of Anti Pimples

We are given an array of integers representing values at different positions. Chaneka can select one or more indices to color black. After that, every element at a position that is a multiple of a black index turns green.

codeforcescompetitive-programmingcombinatoricsnumber-theorysortings
CF 1877A - Goals of Victory

We have a round-robin football tournament with $n$ teams. Every pair of teams plays exactly one match. For each team, its efficiency is defined as: $$text{goals scored} - text{goals conceded}$$ After the tournament finishes, the efficiencies of all teams are computed.

codeforcescompetitive-programmingmath
CF 1878G - wxhtzdy ORO Tree

We are given a tree where each vertex carries a small integer value. For any two vertices $u$ and $v$, we define a function that aggregates all values along the unique simple path between them using bitwise OR. This produces a single number summarizing the entire path.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedata-structuresdfs-and-similarimplementationtrees
CF 1878F - Vasilije Loves Number Theory

We are maintaining a single integer that changes over time, and after each update we need to answer whether it is possible to “complete” it into a very specific divisor structure using an auxiliary number that shares no prime factors with the current value.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1878E - Iva & Pav

We are given an array of integers and multiple queries. Each query specifies a starting index $l$ and a threshold $k$. The task is to find the largest ending index $r ge l$ such that the bitwise AND of the subarray from $al$ to $ar$ is at least $k$.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresgreedy
CF 1878D - Reverse Madness

We are given a string indexed from 1 to n, and the index range is partitioned into k consecutive segments. Each segment i covers a continuous interval from li to ri, and these segments exactly tile the entire string without gaps or overlaps. We then process a sequence of queries.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1878B - Aleksa and Stack

We are asked to build a strictly increasing array of length $n$, where each element is a positive integer, and $n ge 3$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1878A - How Much Does Daytona Cost?

The problem asks whether, given an array of integers and a target integer $k$, there exists at least one contiguous subarray in which $k$ is the element that appears more frequently than any other element.

codeforcescompetitive-programminggreedy
CF 1878C - Vasilije in Cacak

The problem asks whether we can pick exactly k distinct integers from the set {1, 2, ..., n} such that their sum equals x. Each test case provides three integers: n, the upper bound of the numbers we can choose; k, the number of elements we must select; and x, the target sum.

codeforcescompetitive-programmingmath
CF 1879F - Last Man Standing

We are given several independent game configurations, each describing a set of heroes. Each hero has two parameters: health and armor. The game proceeds in discrete rounds, and in every round we choose a fixed damage value x that stays constant for the entire simulation.

codeforcescompetitive-programmingbrute-forcedata-structuresnumber-theory
CF 1879A - Rigged!

We have a weightlifting competition with n athletes. Athlete i has strength si and endurance ei. A barbell weight w is chosen. Any athlete whose strength is less than w cannot lift the barbell at all. Any athlete whose strength is at least w lifts it exactly ei times.

codeforcescompetitive-programminggreedy
CF 1879D - Sum of XOR Functions

We are given an array of non-negative integers. For every subarray $[l,r]$, we compute the XOR of all elements inside that subarray. Let that XOR value be $f(l,r)$. The contribution of a subarray is not just its XOR.

codeforcescompetitive-programmingbitmaskscombinatoricsdivide-and-conquerdpmath
CF 1879E - Interactive Game with Coloring

We are given a rooted tree with $n$ vertices, where vertex 1 is the root. Each vertex $i 1$ has a parent $pi$, so the tree is naturally defined by this parent array.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargraphsimplementationinteractivetrees
CF 1879C - Make it Alternating

We are given a binary string, and we are allowed to delete characters from arbitrary positions. After deleting some characters, we want the remaining string to be alternating, meaning no two adjacent characters are equal.

codeforcescompetitive-programmingcombinatoricsdpgreedy
CF 1879B - Chips on the Board

We are given an $n times n$ grid and two arrays $a$ and $b$, each of length $n$. We want to place chips on some cells so that every cell shares a row or column with at least one chip. Placing a chip on cell $(i, j)$ costs $ai + bj$.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1881G - Anya and the Mysterious String

We are given a string that is continuously modified and queried. Each modification shifts all characters in a segment forward in the alphabet cyclically, like a Caesar shift applied to a range. After each update, we must answer whether a chosen substring is “valid”.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 1881F - Minimum Maximum Distance

We are given a tree and a subset of its vertices marked as special. For every vertex $v$, define $f(v)$ as the distance from $v$ to the farthest marked vertex. We want to choose a vertex whose farthest marked vertex is as close as possible.

codeforcescompetitive-programmingdfs-and-similardpgraphsshortest-pathstrees
CF 1881E - Block Sequence

We are given a sequence of integers, and our goal is to transform it into a "beautiful" sequence using the minimum number of deletions.

codeforcescompetitive-programmingdp
CF 1881D - Divide and Equalize

We are given several independent test cases. In each test case, we start with an array of positive integers. We are allowed to repeatedly pick two different positions and move a multiplicative factor from one value to the other, but the factor must be a divisor of the first…

codeforcescompetitive-programmingmathnumber-theory
CF 1881C - Perfect Square

We are given an $n times n$ matrix of lowercase letters, where $n$ is even. The goal is to transform the matrix into a "perfect square," which is defined as a matrix that remains unchanged when rotated $90^circ$ clockwise.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1881A - Don't Try to Count

We start with a string x. One operation replaces x with x + x, meaning the current string is appended to itself and its length doubles. We are also given a target string s.

codeforcescompetitive-programmingbrute-forcestrings
CF 1881B - Three Threadlets

We are given three positive integers, each representing the length of a thread. In one move, we pick a single thread and split it into two smaller threads with integer lengths, both strictly positive, and their sum equal to the original length.

codeforcescompetitive-programmingmath
CF 1882C - Card Game

We have a deck of cards, each containing an integer value. During the game we repeatedly remove cards from the current deck. If we remove a card at an odd position, its value is added to our score.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1882E2 - Two Permutations (Hard Version)

We are given two independent permutations, one of length $n$ and another of length $m$. We repeatedly apply a synchronized operation: in each step we choose a position in each array, then rotate each array so that the chosen element becomes the last element, preserving…

codeforcescompetitive-programmingconstructive-algorithms
CF 1882E1 - Two Permutations (Easy Version)

We are given two permutations, one of size $n$ and one of size $m$, which are simply arrays containing all integers from 1 to $n$ and 1 to $m$ in some order. The goal is to transform both permutations into their sorted forms simultaneously, using a specific operation.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedynumber-theory
CF 1882B - Sets and Union

We are given several sets of integers. We can choose any subset of these sets (including none) and take the union of the selected sets. A set is attainable if it can be formed in this way.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsgreedy
CF 1882D - Tree XOR

We have a tree where each vertex contains a number. After choosing a root, we may repeatedly pick a vertex and XOR every value inside its subtree by some non-negative integer c. Applying such a spell costs (subtree size) × c.

codeforcescompetitive-programmingbitmasksdfs-and-similardpgreedytrees
CF 1882A - Increasing Sequence

We need to construct a new sequence $b$ of length $n$. Every element of $b$ must be a positive integer. The sequence must be strictly increasing, and for every position $i$, we are forbidden from choosing $bi = ai$.

codeforcescompetitive-programminggreedy
CF 1883G2 - Dances (Hard Version)

We have two arrays of the same size. Before doing anything else, we may reorder each array arbitrarily. An operation removes one element from the first array and one element from the second array.

codeforcescompetitive-programmingbinary-searchgreedysortingstwo-pointers
CF 1883C - Raspberries

We are given an array and a small integer $k$, where $2 le k le 5$. In one operation we may pick any element and increase it by one. The task is to find the smallest number of operations needed so that the product of all array elements becomes divisible by $k$.

codeforcescompetitive-programmingdpmath
CF 1883F - You Are So Beautiful

We are given an array of integers and are asked to count the number of contiguous subarrays whose elements appear as a subsequence in the original array exactly once.

codeforcescompetitive-programmingdata-structures
CF 1883G1 - Dances (Easy version)

We are given two arrays, a and b, each of size n. We are allowed to remove elements from both arrays in pairs, and before doing so, we can reorder the arrays arbitrarily.

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 1883D - In Love

We are asked to maintain a dynamic multiset of segments on the number line, processing additions and deletions one by one. After each operation, we must determine whether the multiset contains at least two segments that do not overlap.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1883E - Look Back

We are given an array of integers, and our task is to transform it into a non-decreasing sequence using the minimum number of operations. The operation allowed is doubling a single element any number of times.

codeforcescompetitive-programmingbitmasksgreedy
CF 1883B - Chemistry

We are asked to determine whether a string can be reduced to a palindrome after removing exactly k characters. The string consists only of lowercase letters, and the number of characters to remove is strictly less than the string length.

codeforcescompetitive-programmingstrings
CF 1883A - Morning

We are asked to enter a four-digit PIN on a device where the digits are arranged in a circle from 0 to 9. The cursor starts at 1. Each second, we can either press the current digit or move the cursor to an adjacent digit.

codeforcescompetitive-programmingmath
CF 1884E - Hard Design

We are given an array of integers and the ability to increment a contiguous segment of the array in a single operation. Each operation has a cost measured as the square of the segment's length, and we earn coins equal to this cost.

codeforcescompetitive-programminggreedyimplementationmath
CF 1884D - Counting Rhyme

We are given an array of integers a[1..n], each between 1 and n. We need to count the number of pairs (i, j) with i < j such that there is no k for which both a[i] and a[j] are divisible by a[k].

codeforcescompetitive-programmingdpmathnumber-theory
CF 1884B - Haunted House

We are given a binary number as a string of length $n$, which may contain leading zeroes. The task is to determine, for each integer $i$ from 1 to $n$, the minimum number of adjacent swaps required to make the number divisible by $2^i$, or indicate if it is impossible.

codeforcescompetitive-programmingbinary-searchgreedymathtwo-pointers
CF 1884C - Medium Design

We are given a very long array, initially all zeros, and a collection of segments on this array. Each segment, if chosen, adds one to every position inside its interval. We are allowed to choose any subset of segments.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 1884A - Simple Design

For each test case, we are given a starting number x and an integer k. A number is considered beautiful if the sum of its decimal digits is divisible by k. The task is to find the smallest integer y such that y ≥ x and the digit sum of y is divisible by k.

codeforcescompetitive-programmingbrute-forcegreedymath
Kvant Math Problem 1525

Place the four collinear points on the $x$ axis as

kvantmathematicsolympiad
CF 1885A - Deterministic Scheduling for Extended Reality over 5G and Beyond

This is not a traditional optimization problem where the judge checks whether you found the best answer. The statement describes a very complicated wireless scheduling model involving users, cells, time slots, frequency blocks, power allocation, interference, frame deadlines…

codeforcescompetitive-programming*special
CF 1886F - Diamond Theft

Each camera can be hacked multiple times. A hack performed at second T disables that camera during the interval [T + 1, T + s]. The only moments that matter are the two thefts. Let the first diamond be stolen at time A and the second at time B, with A < B.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1886E - I Wanna be the Team Leader

We are given a set of programmers, each with a stress tolerance level, and a set of projects, each with a difficulty.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedymathsortingstwo-pointers
CF 1886D - Monocarp and the Set

Think about the process in reverse. Instead of starting with an empty set and inserting numbers, start with the full set {1,2,…,n} and repeatedly remove one number until only one number remains.

codeforcescompetitive-programmingcombinatoricsdata-structuresmath
CF 1886A - Sum of Three

We are given an integer $n$ and must split it into three numbers whose sum is exactly $n$. The three numbers must satisfy three conditions simultaneously. They must all be positive, they must all be distinct, and none of them may be divisible by $3$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1886C - Decreasing String

We are given a string and asked to generate a sequence of strings by removing exactly one character at a time to make the resulting string lexicographically minimal.

codeforcescompetitive-programmingimplementationstrings
CF 1886B - Fear of the Dark

Monocarp starts at the origin $(0,0)$ and wants to reach his home at point $P$. The only illuminated regions come from two lanterns located at points $A$ and $B$. Both lanterns must use the same power $w$, which means each lantern illuminates a disk of radius $w$.

codeforcescompetitive-programmingbinary-searchgeometrymath
CF 1887F - Minimum Segments

We are given a sequence of integers r1, r2, ..., rn, called the characteristic of some unknown sequence a1, a2, ..., an of length n.

codeforcescompetitive-programmingconstructive-algorithms
CF 1887E - Good Colorings

We are asked to interact with a grid of size $n times n$. Initially, $2n$ cells are pre-colored with unique colors from $1$ to $2n$, and the rest are uncolored. In each of up to 10 allowed moves, we can request Alice to color a previously uncolored cell.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgraphsinteractive
CF 1887D - Split

We are given an array of distinct integers ranging from 1 to n, and we are asked to answer multiple queries about contiguous subarrays.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdsumathtreestwo-pointers
CF 1887C - Minimum Array

We are given an array of integers and a sequence of operations that increment segments of the array by a given value. Each operation specifies a contiguous subarray and an integer to add.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsdata-structuresgreedyhashingtwo-pointers
CF 1887B - Time Travel

We are given a fixed set of cities and a sequence of historical snapshots. Each snapshot describes which roads exist between cities at that moment in time. These road systems change completely from one snapshot to another.

codeforcescompetitive-programmingbinary-searchgraphsshortest-paths
CF 1889F - Doremy's Average Tree

I can't reliably write a complete correct editorial for CF 1889F from the problem statement alone. This is a 3500-rated problem, and the official editorial page no longer exposes the written explanation.

codeforcescompetitive-programmingdata-structuresdpgreedytrees
CF 1889E - Doremy's Swapping Trees

We are given two trees on the same labeled vertex set. The labels are fixed and unique, so each node identity is global across both trees.

codeforcescompetitive-programmingdfs-and-similargraphstrees
CF 1889D - Game of Stacks

We are given a collection of $n$ stacks, each containing integers between $1$ and $n$. For each position $i$, we define a function that repeatedly moves to the stack indicated by the top element of the current stack, popping that top element, until it reaches an empty stack.

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementationtrees
CF 1889C2 - Doremy's Drying Plan (Hard Version)

We are given a line of cities and a sequence of rainy days. Each day paints a contiguous segment of cities with rain, and a city is considered dry only if none of the days ever cover it. On top of this fixed schedule, we are allowed to “cancel” exactly $k$ of the rainy days.

codeforcescompetitive-programmingdata-structuresdp
CF 1889A - Qingshan Loves Strings 2

We are given a binary string and allowed to modify it by repeatedly inserting the fixed substring 01 at arbitrary positions. Each insertion increases the length by two characters and keeps all existing characters intact, only shifting them.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1889C1 - Doremy's Drying Plan (Easy Version)

We are asked to find how many cities can be made completely dry over a sequence of days, given that on each day a contiguous segment of cities receives rain. Doremy has a special ability: she can cancel the rain on exactly two of these days.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedysortings
CF 1889B - Doremy's Connecting Plan

We are given a set of cities, each city having a non-negative weight representing population. Initially, there are no connections between any cities.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1890A - Doremy's Paint 3

We are given several test cases, each consisting of an array of positive integers. The task is not to construct a new array from scratch but to decide whether we can reorder the given elements so that every pair of adjacent elements in the resulting sequence has the same sum.

codeforcescompetitive-programmingconstructive-algorithms
CF 1891F - A Growing Tree

We are asked to process a sequence of operations on a growing rooted tree. The tree starts with a single node numbered 1, and each node has a numerical value, initially 0.

codeforcescompetitive-programmingdata-structuresdfs-and-similartrees
CF 1891E - Brukhovich and Exams

We are given a sequence of exams with known difficulties. Smilo considers consecutive exams with coprime difficulties unpleasant. The "sadness" of the year is the total number of consecutive exam pairs whose greatest common divisor is one.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmathsortings
CF 1891A - Sorting with Twos

We are given an array of integers, and the only operation allowed is a kind of prefix subtraction. Specifically, you can pick a prefix of length $2^m$ for any non-negative integer $m$ such that $2^m le n$, and subtract 1 from every element in that prefix.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1891D - Suspicious logarithms

Working

codeforcescompetitive-programmingbinary-searchbrute-forcemath
CF 1891C - Smilo and Monsters

We are given several independent scenarios. In each scenario, there are multiple groups of enemies, each group having some initial size.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedysortingstwo-pointers
CF 1891B - Deja Vu

We have an array of positive integers and a sequence of queries. A query with value x examines every array element. If an element is divisible by 2^x, we add 2^(x-1) to that element.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1893E - Cacti Symphony

We are asked to assign weights from 1 to 3 to every vertex and edge of a graph that is connected and has a very particular structure: any two simple cycles are vertex-disjoint.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgraphs
CF 1893D - Colorful Constructive

We are given a multiset of colored cubes. Cube colors are fixed, but we may choose how to distribute them across shelves and in what order they appear on each shelf. For a shelf, the requirement is about the minimum distance between equal colors.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1893C - Freedom of Choice

Working

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1893B - Neutral Tonality

We are given two arrays. The first array is fixed in order, and the second array is a multiset of extra values we are allowed to insert anywhere into the first array, while also being allowed to permute these inserted values arbitrarily before placing them.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingstwo-pointers
CF 1893A - Anonymous Informant

Working

codeforcescompetitive-programmingbrute-forcedfs-and-similargraphsimplementation
CF 1895G - Two Characters, Two Colors

We are given a binary string where each position carries a value depending on how we color it. Every character can be painted either red or blue. If we choose red at position $i$, we earn $ri$. If we choose blue, we earn $bi$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpflowsgreedy
Kvant Math Problem 1518

Let the common intersection point of the altitudes be $H$.

kvantmathematicsolympiad
CF 1895D - XOR Construction

We are given the XOR values between consecutive elements of an unknown permutation. Let the required permutation be $b$. For every adjacent pair, we know $$bi oplus b{i+1} = ai.$$ The array $b$ must contain every integer from $0$ to $n-1$ exactly once.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdata-structuresmathstring-suffix-structurestrees
CF 1895F - Fancy Arrays

We are counting arrays of length n consisting of non-negative integers. Adjacent values may move by at most k in either direction. An array is considered fancy if at least one element belongs to the interval $$[x, x+k-1].$$ The task is to count all such arrays modulo $10^9+7$.

codeforcescompetitive-programmingcombinatoricsdpmathmatrices
CF 1895E - Infinite Card Game

Each test case describes two players who each own a fixed set of cards. Every card has two numbers, an attack and a defence. A card can defeat another card if its attack is strictly greater than the other card’s defence. The game starts when Monocarp chooses one of his cards.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardpdsugamesgraphsgreedysortingstwo-pointers
CF 1895A - Treasure Chest

The number line contains three important positions. Monocarp starts at position 0, the chest is at position x, and the key is at position y. To open the chest, Monocarp must eventually be standing at the same position as the chest while already carrying the key.

codeforcescompetitive-programmingmath
CF 1895B - Points and Minimum Distance

We start with a multiset of $2n$ integers. The task is to use every number exactly once and pair them up, forming $n$ ordered pairs. Each pair becomes a point in the plane, where the two values are interpreted as its $x$ and $y$ coordinates.

codeforcescompetitive-programminggreedymathsortings
CF 1895C - Torn Lucky Ticket

We are given a collection of ticket fragments, each represented as a string of digits from 1 to 9. A lucky ticket is defined as a string of even length where the sum of digits in the first half equals the sum in the second half.

codeforcescompetitive-programmingbrute-forcedphashingimplementationmath
CF 1896G - Pepe Racing

There are $n^2$ racers with distinct speeds. A race may contain exactly $n$ racers, and the only information returned is the winner of that race.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractivesortings
CF 1896H1 - Cyclic Hamming (Easy Version)

We are given two binary strings, both of length $2^{k+1}$. Some positions are fixed as 0 or 1, while others are unknown and marked with a question mark.

codeforcescompetitive-programmingbrute-forcedivide-and-conquerdpfftmathnumber-theory