brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2155E - Mimo & Yuyu

We are asked to analyze a two-player game on an $n times m$ grid. Each cell can contain tokens, and on a turn, a player picks a token and moves it along a sequence of adjacent cells that always steps leftwards in columns, ultimately depositing new tokens along that path and…

codeforcescompetitive-programminggamesgreedymath
CF 2155F - Juan's Colorful Tree

We are given a tree with n nodes, where each node contains a set of colors drawn from a palette of size k. Each node's set may be different, and the total number of color assignments across all nodes is s.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsmeet-in-the-middletrees
CF 2155D - Batteries

We are given a set of n batteries, some of which work and some of which don't. We do not know how many work, but we do know that at least two do. There is a flashlight that requires exactly two working batteries to turn on.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraph-matchingsgraphsinteractivemath
CF 2155C - The Ancient Wizards' Capes

Each wizard sits at a fixed position from 1 to n, and each one chooses a direction for his cape: either left or right. This choice determines from which positions he becomes visible.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 2155B - Abraham's Great Escape

We are asked to design a maze on an $n times n$ grid where each cell contains an arrow pointing in one of the four cardinal directions: up, down, left, or right. Abraham, starting from any cell, follows the arrow in that cell to the next cell and continues moving in this fashion.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 2155A - El fucho

We are asked to compute the total number of matches in a modified double-elimination football tournament. In this tournament, teams start in a winners' group. Each round, winners' group teams pair up and play matches.

codeforcescompetitive-programmingimplementationmath
CF 2156F1 - Strange Operation (Easy Version)

We are given a permutation of integers from 1 to $n$. The allowed operation selects three indices $i < j < k$ such that the value at $i$ is exactly one more than the maximum of $pj$ and $pk$ and exactly two more than the minimum of $pj$ and $pk$.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementationsortings
CF 2156F2 - Strange Operation (Hard Version)

We start with a permutation of length $n$, meaning every integer from $1$ to $n$ appears exactly once in some order.

codeforcescompetitive-programmingdata-structuresgreedytrees
CF 2156E - Best Time to Buy and Sell Stock

We are given a list of numbers and two players who interact with it in a turn-based process. The key twist is that the final outcome is not chosen directly, but emerges from a game where one player removes elements from consideration and the other permanently freezes elements…

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpgamesgraphsgreedy
CF 2156D - Find the Last Number

We are given a hidden permutation of integers from 1 to $n$, but we only have direct access to the first $n-1$ elements through an interactive query.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2156C - Maximum GCD on Whiteboard

We are given a collection of integers on a whiteboard and two operations to modify it. The first operation, Erase, allows us to remove up to $k$ numbers.

codeforcescompetitive-programminggreedymathnumber-theory
CF 2156B - Strange Machine

We have a circular arrangement of up to 20 machines, each of which either decreases an integer by one (type A) or halves it and floors the result (type B).

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyimplementation
CF 2156A - Pizza Time

We are repeatedly shrinking a pile of pizza slices using a very specific rule until only a tiny remainder is left. The process is deterministic in structure but flexible in how we split the pile, and our only freedom is how we choose that split each day.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 2157I - Hyper Smawk Bros

In Hyper Smawk Bros, two players take turns attacking a boss with health n. Each attack reduces the health by an integer damage x between 1 and m. The catch is that on your turn, you cannot repeat the exact damage your opponent used on the previous turn.

codeforcescompetitive-programmingdpgames
CF 2157H - Keygen 3

We are asked to construct permutations of size $n$ that satisfy two independent structural constraints, and then output as many distinct valid permutations as exist, capped at 2000.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsdfs-and-similarmath
CF 2157F - Git Gud

We are asked to simulate a sequence of missions that guarantees our skill reaches at least a target value n regardless of our starting skill s, which is unknown and can be any integer from 1 to n. Each mission has a difficulty y and a duration l.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdivide-and-conquermathternary-search
CF 2157G - Isaac's Queries

We are dealing with a hidden array of integers, where each integer is in the range [0, 2^30). We are allowed to ask queries about contiguous subarrays.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsdfs-and-similardivide-and-conquerdpgreedyinteractivemathprobabilities
CF 2157E - Adjusting Drones

We are managing a fleet of drones, each with an initial energy level. The rule is that no energy level should appear more than k times.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpdsugreedyimplementationsortings
CF 2157C - Meximum Array 2

We are asked to construct an array of length $n$, where each position holds a non-negative integer, such that a collection of interval constraints is satisfied.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 2157A - Dungeon Equilibrium

We are given an array of integers, and the goal is to make it "balanced." An array is balanced if each number x that appears in it does so exactly x times. So if a number appears too few or too many times, we need to remove some elements to fix it.

codeforcescompetitive-programminggreedyimplementationsortings
CF 2157D - Billion Players Game

We are given a hidden integer position $p$ that will eventually be chosen somewhere inside a fixed interval $[l, r]$. We do not know the exact value, and our goal is to prepare a strategy before seeing $p$.

codeforcescompetitive-programmingbinary-searchgreedymathsortingsternary-searchtwo-pointers
CF 2157B - Expansion Plan 2

We have an infinite 2D grid with a black cell initially at the origin (0, 0). We perform a sequence of expansion operations, each either type "4" or type "8".

codeforcescompetitive-programmingimplementationmath
CF 2158F2 - Distinct GCDs (Hard Version)

We are asked to construct a sequence of length $n$, where each element is a positive integer up to $10^{18}$, with a very specific constraint on neighboring pairs. For every adjacent pair $(ai, a{i+1})$, we compute its gcd.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsgraphsmathnumber-theory
CF 2158F1 - Distinct GCDs (Easy Version)

We are asked to construct a sequence of length $n$, where each element is a large positive integer, and the goal is to control the structure of greatest common divisors between consecutive elements. For every adjacent pair $(ai, a{i+1})$, we compute $gcd(ai, a{i+1})$.

codeforcescompetitive-programmingconstructive-algorithmsgraphsmathnumber-theory
CF 2158E - Sink

We are given a 2D grid of size $n times m$, where each cell contains a positive integer. We can construct "holes" in cells. A cell is considered a sink either if it has a hole, or if it is adjacent (sharing a side) to another sink with a smaller or equal value.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdsugraphsimplementation
CF 2158D - Palindrome Flipping

We are given two binary strings of equal length. Think of them as two rows of switches, where each position is either off or on. The task is to transform the first row into the second by repeatedly choosing a segment and flipping all bits in that segment.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphsimplementationshortest-pathsstrings
CF 2158B - Split

We are given an array of length $2n$. We must split its elements into two subsequences $p$ and $q$, each containing exactly $n$ elements. Order inside a subsequence does not matter, only the multiset of chosen values matters.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2158C - Annoying Game

We are given an array $a$ and another array $b$ of the same length. Two players alternate turns for exactly $k$ moves. On each move, the current player picks an index and either adds or subtracts the corresponding value $bi$ from $ai$.

codeforcescompetitive-programmingdpgamesgreedy
CF 2158A - Suspension

We are given a football match with a fixed number of players, and a sequence of disciplinary actions in the form of yellow and red cards. Each yellow card contributes toward a potential suspension, and each red card immediately suspends a player.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2159F - Grand Finale: Snakes

We are given a permutation grid of size $n times n$, where every number from $1$ to $n^2$ appears exactly once. Instead of directly using this grid, we interact with a hidden process that defines, for each snake length $l$ and time $T$, a value $f(l,T)$.

codeforcescompetitive-programmingbinary-searchinteractiveternary-search
CF 2159E - Super-Short-Polynomial-San

We are given a quadratic polynomial in one variable, and we repeatedly raise it to a power that changes per query.

codeforcescompetitive-programmingmathmeet-in-the-middle
CF 2159D1 - Inverse Minimum Partition (Easy Version)

We are asked to partition a sequence of positive integers into contiguous subarrays such that each subarray has a cost defined by the ratio of its last element to its minimum element, rounded up. Formally, for a subarray $b$, the cost is $lceil bk / min(b1, dots, bk) rceil$.

codeforcescompetitive-programmingbinary-searchbrute-forcedpgeometrygreedymathtwo-pointers
CF 2159D2 - Inverse Minimum Partition (Hard Version)

We are asked to work with sequences of positive integers. For any contiguous subsequence $b$ of a sequence $a$, there is a notion of cost: it is the ceiling of the last element of $b$ divided by the minimum of all elements in $b$.

codeforcescompetitive-programmingdpgreedymath
CF 2159A - MAD Interactive Problem

We are tasked with reconstructing a hidden sequence of length $2n$ in which each number from $1$ to $n$ appears exactly twice. The only tool we have is the MAD query.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractive
CF 2159C - Twin Polynomials

We are given a polynomial $f(x)$ of degree $n$ where some coefficients are known and others are undetermined (represented by $-1$).

codeforcescompetitive-programmingcombinatoricsgraph-matchingsmath
CF 2159B - Rectangles

We are given a grid filled with zeros and ones. For every cell in this grid, we want to know the smallest possible “valid rectangle” that covers it, where validity is defined in a very specific way: the rectangle must have ones at all four corners, not necessarily inside.

codeforcescompetitive-programmingbrute-forcedata-structuresdpdsugreedyimplementationtwo-pointers
CF 2160A - MEX Partition

We are given a multiset of integers, and we are allowed to split it into several smaller multisets such that every original element is used exactly the same number of times overall. In other words, we are partitioning occurrences of numbers into groups.

codeforcescompetitive-programmingmath
CF 2161H - Cycle Sort

We are given two arrays, one of length $n$ and one of length $m$, and together they contain every number from $1$ to $n+m$ exactly once. You can think of the elements as being split into two buckets. We then simulate a long sequence of $k$ steps.

codeforcescompetitive-programmingdata-structures
CF 2161E - Left is Always Right

We are given a binary string where some positions are fixed as 0 or 1, while others are unknown and can be chosen freely. Once we assign values to all unknowns, we obtain a fully concrete binary array of length n.

codeforcescompetitive-programmingcombinatoricsimplementationmath
CF 2161G - Bitwise And Equals

We are given an array of integers and, for each query value X, we are allowed to increase individual elements of the array by repeatedly adding one. Each query is independent, and we always start from the same initial array.

codeforcescompetitive-programmingbitmasksgreedy
CF 2161F - SubMST

We are asked to compute a global sum over all subsets of vertices in a tree. The input is an unweighted tree with n vertices. From this tree, we imagine a complete graph where the weight between any two vertices equals the distance between them in the original tree.

codeforcescompetitive-programmingcombinatoricsgraphstrees
CF 2161D - Locked Out

We are given an array and we are allowed to delete elements from it. After deletions, we want the remaining sequence to satisfy a very specific restriction: it must not contain two elements where the later element is exactly one larger than the earlier element.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedy
CF 2161C - Loyalty

We are asked to maximize bonus points in a store where every purchase can potentially increase our loyalty level. Each item has a price between 1 and some loyalty factor $X$. Initially, our loyalty level is calculated as the integer division of our total spend $S$ by $X$.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortingstwo-pointers
CF 2161B - Make Connected

We are given an $n times n$ grid with black cells marked and white cells marked .. Our goal is to paint some white cells black so that three conditions are met simultaneously. First, there must be at least one black cell.

codeforcescompetitive-programmingbrute-forceimplementation
CF 2161A - Round Trip

We are simulating a sequence of contest rounds where a participant can sometimes adjust their rating before each rated round.

codeforcescompetitive-programminggamesgreedyimplementationmath
CF 2162H - Beautiful Problem

We are given an array whose values are fixed, but we are allowed to permute them arbitrarily before answering queries. Alongside this array, we are also given several index ranges.

codeforcescompetitive-programmingdp
CF 2162G - Beautiful Tree

We are asked to construct a labeled tree with $n$ vertices such that the sum of the products of the labels of each edge is a perfect square. Formally, if the tree has edges $(u, v)$, we compute $S = sum (u cdot v)$, and $S$ must equal $x^2$ for some integer $x$.

codeforcescompetitive-programmingconstructive-algorithmsmathprobabilitiestrees
CF 2162F - Beautiful Intervals

We are given several test cases. In each test case, we must construct a permutation of the numbers from 0 to n−1. Think of this permutation as placing each number exactly once on a line of length n. On top of this array, we are given m intervals.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2162E - Beautiful Palindromes

We are given an array of integers between 1 and n and an integer k. We are allowed to append exactly k numbers to the end of this array.

codeforcescompetitive-programmingconstructive-algorithmsgreedyschedules
CF 2162D - Beautiful Permutation

We are given a hidden permutation of size $n$, meaning it contains each number from $1$ to $n$ exactly once. After this permutation was fixed, someone chose a segment $[l, r]$ and increased every element inside that segment by exactly one.

codeforcescompetitive-programmingbinary-searchinteractive
CF 2162C - Beautiful XOR

We are given two integers a and b. We can repeatedly pick an integer x such that 0 ≤ x ≤ a (the current value of a) and replace a with a XOR x.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 2162B - Beautiful String

We are given a binary string s of length n, which means it contains only '0' and '1'. The task is to select a subsequence p from s such that two conditions hold: first, p must be non-decreasing (so all '0's must appear before any '1's in p), and second, if we remove all…

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 2162A - Beautiful Average

We are given an array of integers, each between 1 and 10, and we are asked to find the maximum average of any contiguous subarray. A subarray is simply a consecutive segment of the array, which can be as short as a single element or as long as the entire array.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2163E - Plegma

We are dealing with a two-phase interactive problem. In the first phase, Player A receives a full $n times n$ binary grid, where each cell is either a 0 or a 1, and each test case also specifies whether the grid is fully connected through 1s or not.

codeforcescompetitive-programmingbitmaskscombinatoricscommunicationinteractive
CF 2163D2 - Diadrash (Hard Version)

We are given a hidden permutation of the integers from 0 to n−1, and a collection of fixed segments of this permutation. For each segment, we are interested in its mex, the smallest non-negative integer that does not appear inside that segment.

codeforcescompetitive-programmingbinary-searchinteractivemathsortings
CF 2163D1 - Diadrash (Easy Version)

We are given a hidden permutation of integers from 0 to n-1, and our task is to find the maximum MEX over a set of ranges. Each range specifies a contiguous segment of the permutation, and the MEX of a range is the smallest non-negative integer missing from that segment.

codeforcescompetitive-programmingbinary-searchbrute-forcedivide-and-conquerimplementationinteractive
CF 2163A - Souvlaki VS. Kalamaki

We are given a sequence of integers, and two players take turns acting on consecutive pairs of elements. On each turn, the current player may either skip or swap the current element with the next.

codeforcescompetitive-programmingbrute-forcegreedymathsortings
CF 2163B - Siga ta Kymata

We are given a permutation of integers from 1 to $n$, and a binary string $x$ of the same length. Initially, we have another binary string $s$ of zeros.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 2163C - Monopati

We are given a 2-row grid with $n$ columns, where each cell contains a distinct integer from $1$ to $2n$. For any interval of integers $[l, r]$, we can generate a binary grid where a cell is marked 1 if its original value falls inside that interval, otherwise 0.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathtwo-pointers
CF 2164H - PalindromePalindrome

We are given a long base string and many independent queries, each asking about a contiguous segment. For any queried segment, we are interested in all substrings that are palindromes and that appear at least twice inside that segment.

codeforcescompetitive-programmingdata-structuresstrings
CF 2164G - Pointless Machine

We are dealing with a hidden tree on $n$ labeled vertices, but we cannot see its edges directly. Instead, we can “probe” the tree using permutations. Each query is a full ordering of the vertices.

codeforcescompetitive-programmingconstructive-algorithmsgraphsinteractivetrees
CF 2164F2 - Chain Prefix Rank (Hard Version)

We are given a rooted tree where every vertex has a fixed parent, and thus a fixed ancestor structure. Alongside this tree, each vertex $u$ comes with a target number $au$.

codeforcescompetitive-programmingbinary-searchcombinatoricsdata-structuresdfs-and-similardpgraphsmathtrees
CF 2164F1 - Chain Prefix Rank (Easy Version)

We are given a rooted tree with $n$ nodes, labeled from $1$ to $n$, with node $1$ as the root. For each node $u$, a number $au$ is specified.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpmathtrees
CF 2164E - Journey

We are given an undirected connected graph with vertices and weighted edges. We start at vertex 1 and must traverse the graph such that every edge is marked at least once, returning to the start.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedy
CF 2164D - Copy String

We start with a string s and want to turn it into another string t, both of the same length. The only allowed move does not directly edit characters; instead, it rebuilds the entire string at once using a very constrained rule.

codeforcescompetitive-programminggreedyimplementationstringstwo-pointers
CF 2164C - Dungeon

We are asked to simulate a dungeon scenario where you have a set of swords, each with a damage value, and a set of monsters, each with a life value. You can kill a monster if your sword’s damage is at least equal to the monster’s life.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresgreedysortings
CF 2164B - Even Modulo Pair

We are given several test cases. In each one, we receive a strictly increasing list of positive integers. The task is to choose two different elements from this list, call them $x$ and $y$, with the restriction that $x < y$, such that when we divide $y$ by $x$, the remainder…

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 2164A - Sequence Game

We are given a sequence of numbers, and we repeatedly compress it until only one value remains. Each operation takes two adjacent elements, removes them, and replaces them with any integer lying between the two original values, inclusive.

codeforcescompetitive-programmingbrute-forcesortings
CF 2165F - Arctic Acquisition

We are given a permutation of length $n$, which is an array of distinct integers from 1 to $n$ arranged in some order. The task is to count the number of contiguous subarrays (intervals) that contain a specific pattern, called a 21435-subsequence.

codeforcescompetitive-programmingdata-structuresgreedy
CF 2165C - Binary Wine

We are given an array of integers, and each element acts like a cap: for each position $i$, we are allowed to choose a value $bi$ anywhere between $0$ and $ai$, inclusive. From this chosen vector $b$, we look at the XOR of all its elements.

codeforcescompetitive-programmingbitmasksgreedymath
CF 2165E - Rainbow Branch

We are given a tree and we need to assign colors to its edges. The restriction is that we must use exactly $k$ distinct colors, each appearing at least once. Once the coloring is fixed, consider any two vertices and look at the simple path between them.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedytrees
CF 2165D - Path Split

We are given a sequence of integers. Our goal is to split this sequence into the smallest number of subsequences where each subsequence is “consecutive in value.” That is, within a subsequence, every adjacent pair differs by exactly one.

codeforcescompetitive-programminggraph-matchingsgreedy
CF 2165B - Marble Council

We are given a multiset of integers, which we can think of as a bag of marbles where each marble has a color represented by a number.

codeforcescompetitive-programmingdpmathsortings
CF 2165A - Cyclic Merging

We are asked to merge elements arranged in a circle. Each element is a non-negative integer, and two elements are considered adjacent if they are next to each other in the array or if one is at the start and the other at the end.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2167G - Mukhammadali and the Smooth Array

We are given an integer array and a corresponding cost array. For each position in the array, we can replace its value at a certain cost, and positions we do not change keep their original values.

codeforcescompetitive-programmingdata-structuresdp
CF 2167F - Tree, TREE!!!

We are given an unrooted tree and a parameter $k$. For every possible choice of a root $r$, we conceptually “re-root” the tree at $r$ and then look at all ways of selecting exactly $k$ distinct nodes.

codeforcescompetitive-programmingdfs-and-similardpmathtrees
CF 2167E - khba Loves to Sleep!

We are given a one-dimensional segment from 0 to x, and a set of n friends sitting at fixed integer positions on this segment. We are allowed to place k teleport points anywhere on the segment, all at distinct integer positions.

codeforcescompetitive-programmingbinary-searchdata-structuresgeometrygreedyimplementation
CF 2167D - Yet Another Array Problem

Each test case gives a collection of large integers, and the task is to find the smallest integer $x ge 2$ such that at least one element in the array is coprime with $x$.

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 2167C - Isamatdin and His Magic Wand!

We are given several independent test cases. Each test case consists of a sequence of integers representing toys arranged in a line. The only operation allowed is swapping two elements if one is even and the other is odd. Swaps between two evens or two odds are forbidden.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationsortings
CF 2167B - Your Name

We are given two strings, s and t, each of length n. The first string represents a row of lettered cubes, and the second string is a target name. The task is to determine if it is possible to rearrange the letters of s to exactly match t.

codeforcescompetitive-programmingsortingsstrings
CF 2167A - Square?

We are given four stick lengths per test case, and we want to know whether these four sticks can be arranged to form the boundary of a square.

codeforcescompetitive-programmingmathsortings
CF 2168C - Intercepting Butterflies

Alice has a secret integer x between 1 and 2^15 that she wants to communicate to Bob using a set S drawn from the integers 1 through 20. The twist is that when Bob receives S, one element may have been added, one may have been removed, or S may be unchanged.

codeforcescompetitive-programmingbitmaskscommunicationconstructive-algorithmsgraphsinteractive
CF 2168B - Locate

Something went wrong. If this issue persists please contact us through our help center at help.openai.com.

codeforcescompetitive-programmingbinary-searchcombinatoricscommunicationconstructive-algorithmsgreedyinteractive
CF 2168A1 - Encode and Decode (Easy Version)

We are asked to design a two-phase program that communicates an array of integers through a single string. On the first run, the program receives an array of length n, where each element is at most 26.

codeforcescompetitive-programmingcommunicationconstructive-algorithmsinteractive
CF 2168A2 - Encode and Decode (Hard Version)

We are asked to implement a two-phase encoding and decoding process for an array of integers. In the first phase, the program receives an array a of size n with values up to one billion and must output a string s composed of lowercase letters.

codeforcescompetitive-programmingbitmaskscommunicationinteractivemath
CF 2169F - Subsequence Problem

We are asked to count arrays of length $n$ over the integers from 1 to $m$ that are “perfect” with respect to $k$ given sets of numbers. Each set defines the allowable value for a position in a hypothetical “beautiful” array of length $k$.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 2169D2 - Removal of a Sequence (Hard Version)

We are given an infinite sequence of natural numbers starting from 1. Polycarp performs a special removal operation exactly $x$ times. Each operation removes all numbers in positions that are multiples of $y$ in the current sequence.

codeforcescompetitive-programmingbinary-searchdivide-and-conquergreedyimplementationmathnumber-theory
CF 2169E - Points Selection

We are asked to model a two-player game on a set of points in the plane, where each point has a cost. Alice removes some points with the goal of maximizing a total score, and Bob then draws the smallest axis-aligned rectangle containing all remaining points to minimize the score.

codeforcescompetitive-programmingdpgreedy
CF 2169D1 - Removal of a Sequence (Easy Version)

We start with an infinite sequence of natural numbers, effectively thinking of it as the array 1, 2, 3, 4, .... The process repeatedly removes elements based on a fixed step size y: every time we apply an operation, we delete the elements sitting at positions y, 2y, 3y, ...

codeforcescompetitive-programmingbinary-searchimplementationmathnumber-theory
CF 2169B - Drifting Away

We are given a one-dimensional river represented as a string of cells. Each cell has one of three behaviors: it can push Monocarp left, push him right, or do nothing. Monocarp chooses a starting cell and then moves step by step in discrete time.

codeforcescompetitive-programminggreedyimplementation
CF 2169A - Alice and Bob

Each test case gives a sorted list of marble values and a fixed integer chosen by Alice. Bob must pick his own integer, and then every marble independently awards its point to whoever is closer to that marble’s value, with Alice winning ties.

codeforcescompetitive-programminggreedyimplementation
CF 2169C - Range Operation

We are given an array of integers and allowed to perform a single operation at most once: choose a contiguous subarray and replace all its elements with the sum of its 1-based endpoints.

codeforcescompetitive-programmingdpgreedymathtwo-pointers
CF 2170F - Build XOR on a Segment

We are asked to process multiple queries on an array of integers, where each query specifies a segment of the array and a target number. For each query, we need to find the smallest subset of elements within that segment whose XOR equals the target.

codeforcescompetitive-programmingbitmasksdp
CF 2170E - Binary Strings and Blocks

We are asked to count binary strings of length n that satisfy multiple “beauty” constraints on certain substrings. A block is a maximal contiguous sequence of identical characters.

codeforcescompetitive-programmingcombinatoricsdata-structuresdp
CF 2170D - Almost Roman

We are given a string consisting of the characters 'X', 'V', 'I', and '?'. Each letter has a numeric value: 'X' is worth 10, 'V' is worth 5, and 'I' is usually worth 1, but if it is immediately followed by an 'X' or 'V', it counts as -1.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 2170B - Addition on a Segment

We are given an array of length $n$, initially all zeros. We perform exactly $n$ operations, and each operation adds $1$ to every element of some chosen contiguous segment.

codeforcescompetitive-programminggreedymath
CF 2170A - Maximum Neighborhood

We are asked to consider an $n times n$ grid of integers filled sequentially row by row. The first row contains numbers from $1$ to $n$, the second from $n+1$ to $2n$, and so on until the $n$-th row, which contains numbers from $n^2-n+1$ to $n^2$.

codeforcescompetitive-programmingbitmasksbrute-forcegreedyimplementationmath
CF 2170C - Quotient and Remainder

We are given two multisets of integers, one called $q$ and one called $r$, along with an upper bound $k$. The only way to remove elements is by pairing one value from $q$ with one value from $r$ through a hidden construction involving two integers $x$ and $y$, where $1 le y <…

codeforcescompetitive-programmingbinary-searchgreedytwo-pointers
CF 2171G - Sakura Adachi and Optimal Sequences

We are given two arrays of the same length, a and b, where each element of a is at most the corresponding element in b. The task is to transform a into b using two allowed operations: incrementing a single element of a by 1, or doubling all elements in a.

codeforcescompetitive-programmingbitmaskscombinatoricsgreedymath
CF 2171H - Shiori Miyagi and Maximum Array Score

The task asks us to construct an array of length n with strictly increasing integers, all bounded by m, such that a particular score is maximized. The score is the sum of v(i, ai) from i=2 to n, where v(b, x) is the largest power k such that b^k divides x.

codeforcescompetitive-programmingbinary-searchdata-structuresdpsortings