brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 2149E - Hidden Knowledge of the Ancients

We are given a sequence of integers representing symbols on an ancient tablet. Each test case asks us to count the number of continuous segments (subarrays) of this sequence that satisfy two conditions: the segment contains exactly k distinct numbers, and its length is at…

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 2149A - Be Positive

We are given an array of length $n$ where each element is either $-1$, $0$, or $1$. We are allowed to increment any element by one any number of times. The goal is to make the product of all elements strictly positive while performing the fewest possible operations.

codeforcescompetitive-programmingmath
CF 2149B - Unconventional Pairs

We are given an even-length array of integers representing participants in a show. The task is to form pairs of participants such that each participant is in exactly one pair, and the difference between the two numbers in a pair is minimized in a global sense.

codeforcescompetitive-programminggreedysortings
CF 2149C - MEX rose

We are given an array of integers, each between 0 and n, and a target number k. We can replace any element with any integer from 0 to n in a single operation. Our goal is to make the MEX of the array equal to k using the minimum number of replacements.

codeforcescompetitive-programminggreedy
CF 2150G - Counting Is Fun: The Finale

We are asked to count how many binary strings of fixed length and fixed composition can be formed such that two conditions hold simultaneously: the string must dominate a given reference string in lexicographic order, and it must admit at least one split point where both…

codeforcescompetitive-programmingcombinatoricsimplementation
CF 2150F - Cycle Closing

We are given a connected simple undirected graph. The graph is already partially filled with edges, and our goal is to make it a complete graph, meaning every pair of distinct vertices must end up connected by an edge. We are not allowed to directly add edges.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementationshortest-pathstrees
CF 2150E2 - Hidden Single (Version 2)

We are given a hidden array of length $2n-1$ that contains each number from 1 to $n$ exactly twice, except for a single number which appears only once. Our goal is to determine which number appears only once. We do not need to know its position, only its identity.

codeforcescompetitive-programmingbinary-searchdivide-and-conquerinteractivemathprobabilities
CF 2150E1 - Hidden Single (Version 1)

We are given a hidden array of length 2n-1, containing integers from 1 to n such that every number appears exactly twice except for one number that appears only once. Our goal is to identify the number that occurs exactly once. We do not need its position, only its value.

codeforcescompetitive-programmingdivide-and-conquerinteractivemathprobabilitiessortings
CF 2150D - Attraction Theory

We start with n people placed on positions 1 through n on a line. The initial configuration is completely rigid: person i starts at position i.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2150B - Grid Counting

We are asked to count the number of ways to color cells black in an $n times n$ grid given a list $a$ of length $n$. The entry $ak$ specifies how many black cells must appear in row $k$.

codeforcescompetitive-programmingcombinatoricsimplementationmath
CF 2150C - Limited Edition Shop

We are asked to analyze a situation where two players, Alice and Bob, pick objects from a shop in turn. Each object has a value from our perspective, and each player has their own preference order.

codeforcescompetitive-programmingdata-structuresdp
CF 2150A - Incremental Path

We are given a line of $10^9$ cells, each either black or white. Initially, a certain set of cells are black, and all others are white.

codeforcescompetitive-programmingdata-structureshashingimplementation
CF 2152H1 - Victorious Coloring (Easy Version)

We are given a tree with n vertices, each edge has a positive weight. The task is to assign nonnegative integer weights to the vertices themselves so that when we compute the minimum cost of a “victorious coloring” (coloring vertices red or yellow with at least one red)…

codeforcescompetitive-programmingdfs-and-similardpgreedy
CF 2152H2 - Victorious Coloring (Hard Version)

We are given a tree with weighted edges, and we are asked to assign nonnegative weights to vertices so that a certain “victorious coloring” has a minimum cost at least some value l, while keeping the sum of vertex weights as small as possible.

codeforcescompetitive-programmingdata-structuresgreedyschedules
CF 2152F - Triple Attack

We are given a sorted sequence of attack timestamps. Each query gives a contiguous segment of this sequence, and inside that segment we are allowed to delete some elements. The goal is to keep as many timestamps as possible while avoiding a specific failure condition.

codeforcescompetitive-programmingdata-structuresgreedy
CF 2152G - Query Jungle

We are given a rooted tree with root fixed at vertex 1. Some vertices are marked as “active” (contain a monster), others are not.

codeforcescompetitive-programmingdata-structuresimplementationmathmatricestrees
CF 2152A - Increase or Smash

We are given an array of zeros of length $n$, and a target array of positive integers. We want to reach the target array with as few operations as possible. There are two operations available. The first, Increase, adds the same positive integer to every element of the array.

codeforcescompetitive-programminggreedyimplementation
CF 2152E - Monotone Subsequence

We are given a hidden permutation of length $n^2 + 1$ and we need to find a monotone subsequence of length exactly $n+1$. The subsequence can either be increasing or decreasing.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyinteractivemath
CF 2152D - Division Versus Addition

We are given an array where every element starts at least 2, and two players repeatedly modify it until every value becomes 1.

codeforcescompetitive-programminggamesgreedymath
CF 2152B - Catching the Krug

We are asked to compute the maximum number of turns the Krug can survive against Doran on a square grid. The grid has coordinates from 0 to n in both rows and columns. The Krug moves first, either staying in place or moving to a vertically or horizontally adjacent cell.

codeforcescompetitive-programminggames
CF 2152C - Triple Removal

We are given a binary array, meaning each element is either 0 or 1, and we need to repeatedly remove triples of identical elements. Each removal has a cost defined as the minimum distance between consecutive elements in the triple.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 2153F - Odd Queries on Odd Array

We are given an array a of length n that satisfies a special property called "cute," which prevents certain repeating patterns of four indices.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresimplementationtrees
CF 2153D - Not Alone

We are given a circular sequence of integers, and we are allowed to change each value by paying unit cost per increment or decrement.

codeforcescompetitive-programmingdpgreedy
CF 2153E - Zero Trailing Factorial

We are asked to work with trailing zeros of factorials in arbitrary bases. Specifically, for any integer $xge 1$ and base $kge 2$, $vk(x!)$ counts how many times $k$ divides $x!$. For prime bases, this is straightforward: sum the integer divisions of $x$ by powers of $p$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 2153C - Symmetrical Polygons

We are given several collections of stick lengths, and for each collection we want to pick some of these sticks to form the sides of a polygon. Each chosen stick becomes exactly one side, so we are not allowed to split or merge sticks.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedyimplementationsortings
CF 2153A - Circle of Apple Trees

We are given a circle of apple trees, each bearing a single apple with an associated beauty value. You start at tree one and walk around the circle repeatedly. At each tree, you have the choice to eat the apple or skip it.

codeforcescompetitive-programminggreedysortings
CF 2153B - Bitwise Reversion

We are asked to determine whether it is possible to construct three non-negative integers, $a$, $b$, and $c$, such that their pairwise bitwise ANDs equal three given integers $x$, $y$, and $z$. Specifically, the constraints are that $a & b = x$, $b & c = y$, and $a & c = z$.

codeforcescompetitive-programmingbitmasksgreedy
CF 2154F2 - Bombing (Hard Version)

We are asked to count the number of ways to fill in missing values in a partially specified permutation such that the resulting permutation can be split into two consecutive subsequences whose combined order gives the sorted permutation from $1$ to $n$.

codeforcescompetitive-programmingcombinatoricsdp
CF 2154F1 - Bombing (Easy Version)

We are given an array of length $n$ that is supposed to be a permutation of $1 dots n$, but some positions are unknown and marked as $-1$.

codeforcescompetitive-programmingbrute-forcecombinatoricsconstructive-algorithmsimplementationmath
CF 2154D - Catshock

The tree represents a world where a cat starts at node 1 and tries to reach node n. You cannot directly control the cat’s path when it moves.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstreestwo-pointers
CF 2154E - No Mind To Think

We are given an array of positive integers. We are allowed to choose one odd length $x$, and then repeatedly perform an operation up to $k$ times. Each operation picks any subsequence of length $x$, computes its median, and overwrites all chosen elements with that median value.

codeforcescompetitive-programmingbinary-searchdivide-and-conquergreedysortingsternary-searchtwo-pointers
CF 2154C2 - No Cost Too Great (Hard Version)

We are given an array of integers a, where each element behaves like a “value sitting on a position”, and a second array b which describes how expensive it is to increase each corresponding a[i] by 1.

codeforcescompetitive-programminggreedymathnumber-theory
CF 2154B - Make it Zigzag

We are given an array of integers and want to transform it into a zigzag sequence. A zigzag array is one where each element alternates between being smaller and larger than its neighbor: the first element is smaller than the second, the second is larger than the third, and so on.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2154A - Notelock

We are given a binary string consisting of 0s and 1s and a positive integer k. Each 1 in the string can be “turned off” by Teto according to a simple local rule: if a 1 is not protected and there are no other 1s in the previous k-1 positions, it can be changed to 0.

codeforcescompetitive-programminggreedytwo-pointers
CF 2154C1 - No Cost Too Great (Easy Version)

We are given an array of positive integers a of length n. For each element ai, we can increment it by 1 any number of times at a cost of 1 per increment.

codeforcescompetitive-programminggreedyimplementationmathnumber-theory
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