brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1937E - Pokémon Arena

We can think of this problem as walking through a sequence of Pokémon, where each Pokémon is a node with a cost to “enter combat” and several strength values across different attributes.

codeforcescompetitive-programminggraphsshortest-pathssortings
CF 1937C - Bitwise Operation Wizard

We are interacting with a hidden permutation of numbers from 0 to n-1, but we never see it directly. Instead, we are allowed to compare expressions of the form (p[a] Our goal is not to reconstruct the permutation, but to find two indices i and j such that the XOR of their…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractive
CF 1937D - Pinball

We are given a line of cells, each cell containing a direction character that behaves like a deterministic instruction for a moving token. When a token is dropped onto a cell, it repeatedly moves one step left or right depending on the current cell’s character.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationtwo-pointers
CF 1930H - Interactive Mex Tree

We are dealing with a tree, but the real structure we care about is hidden behind an interactive layer. In every test case, we must output two permutations of node labels.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarinteractivetrees
CF 1930F - Maximize the Difference

We build an array incrementally. After every insertion we must compute $$f(a)=maxx left(maxi(aimid x)-mini(aimid x)right).$$ The value inserted at each step is encrypted by the previous answer, so the queries must be processed online.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similar
CF 1930G - Prefix Max Set Counting

We are asked to count the number of distinct prefix maximum sequences that can appear over all valid pre-order traversals of a rooted tree.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1930B - Permutation Printing

We are asked to construct a permutation of numbers from 1 to n such that a specific forbidden pattern never appears. The pattern involves two different starting positions i and j.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmath
CF 1930D1 - Sum over all Substrings (Easy Version)

We are given a binary string, and for each of its substrings, we want to compute the minimum number of ones required to form a “good” string with respect to that substring.

codeforcescompetitive-programmingbrute-forcedpgreedystrings
CF 1930C - Lexicographically Largest

We are given an array a of length n. The task is to repeatedly select an element from a, add its value plus its current index to a set S, remove it from the array, and continue until a is empty. After all insertions, we sort the set S in decreasing order to form array b.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedysortings
CF 1929F - Sasha and the Wedding Binary Search Tree

We are asked to count how many ways we can assign integer values to the vertices of a rooted binary tree such that it forms a valid binary search tree, with all values constrained between $1$ and $C$.

codeforcescompetitive-programmingbrute-forcecombinatoricsdata-structuresdfs-and-similarmathtrees
CF 1929E - Sasha and the Happy Tree Cutting

We are given a tree with n vertices and a set of k pairs of vertices. Sasha wants to ensure that for each pair (ai, bi), there is at least one colored edge on the simple path connecting ai and bi.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpgraphsgreedymathtrees
CF 1929C - Sasha and the Casino

Sasha plays a repeated betting game where each bet either multiplies his stake by a factor or loses it entirely. The only control he has is the size of each bet, and he is allowed to adapt it based on past outcomes.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgamesgreedymath
CF 1929D - Sasha and a Walk in the City

We are asked to count the number of subsets of intersections in a tree such that, if we declare exactly the intersections in the subset as dangerous, no simple path in the tree contains three or more dangerous intersections.

codeforcescompetitive-programmingcombinatoricsdpmathtrees
CF 1929B - Sasha and the Drawing

We have an $n times n$ grid. Every cell belongs to exactly one diagonal of each of the two diagonal directions. The problem counts both directions, so the grid contains a total of $2n-1$ diagonals of one type and $2n-1$ diagonals of the other type, for a total of $4n-2$…

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1925F - Fractal Origami

We repeatedly perform the same fold on a square sheet. Each operation folds all four corners to the center, producing a smaller square rotated by $45^circ$. After doing this $N$ times and unfolding the paper, every crease is either a mountain fold or a valley fold.

codeforcescompetitive-programminggeometrymath
CF 1925C - Did We Get Everything Covered?

This is a Type B (prove/disprove) problem. The task is to determine whether a stated property is always true: Given a closed ski track that passes through each village exactly twice, is it always possible to traverse along the track so as to visit each village exactly once?

codeforcescompetitive-programmingconstructive-algorithmsdpgreedyimplementationstrings
CF 1925A - We Got Everything Covered!

We are asked to build a single string over the first k lowercase letters such that every possible string of length n formed from those k letters appears somewhere inside it as a subsequence.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1925E - Space Harbour

We have a line with n positions, each containing a ship. Certain positions have harbours, each with an associated value. Every ship must eventually "move" to the next harbour to its right.

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 1917E - Construct Matrix

We are asked to construct an $n times n$ matrix of zeros and ones with two simultaneous constraints on the bitwise XORs of rows and columns, and an overall sum constraint.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1917A - Least Product

We are given an array of integers and the ability to decrease each number to any integer between zero and its current value. For positive numbers, this means we can reduce them to zero; for negative numbers, we can increase them toward zero.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1917C - Watering an Array

We start with an array a of length n. For each of the next d days we must choose exactly one action. The first action increases the prefix [1..bi] by one, where the sequence b is generated by repeating the given array v forever. The second action scores points.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1917D - Yet Another Inversions Problem

We are building a long array by interleaving two independent permutations in a structured way. One permutation, call it $p$, provides odd base values. The second permutation, $q$, determines powers of two.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpimplementationmathnumber-theory
CF 1906K - Deck-Building Game

Each card can end up in one of three states. A card may be placed in your deck, placed in your friend's deck, or discarded entirely. Let the XOR of your deck be X and the XOR of your friend's deck be Y.

codeforcescompetitive-programmingdivide-and-conquermath
CF 1906D - Spaceship Exploration

We are working in a geometric setting where a large convex polygon represents a forbidden region. A spaceship starts outside this region and must travel to another point, with the constraint that it is never allowed to enter the interior of the polygon, though touching its…

codeforcescompetitive-programmingbinary-searchgeometry
CF 1906I - Contingency Plan 2

The network is a tree, so initially there is exactly one simple path between every pair of computers. Each edge, when put into emergency mode, becomes a directed constraint: one endpoint must come before the other in a global ordering of all nodes.

codeforcescompetitive-programminggraph-matchings
CF 1906H - Twin Friends

We are given two strings, $A$ of length $N$ and $B$ of length $M$ with $N le M$, representing the names of two twins. We want to create nicknames $A'$ and $B'$ for them.

codeforcescompetitive-programmingcombinatoricsdp
CF 1906E - Merge Not Sort

We are asked to reverse-engineer the merge step of a Merge Sort-like routine, but with a twist: the two input arrays may not be sorted. Concretely, we receive a single array C of length 2N containing every integer from 1 to 2N exactly once.

codeforcescompetitive-programmingconstructive-algorithmsdp
CF 1906B - Button Pressing

We have a line of lamps, each either on or off, and a line of buttons, one per lamp. Each button affects only the lamps immediately adjacent to it: pressing button $i$ toggles lamps $i-1$ and $i+1$, if they exist.

codeforcescompetitive-programmingbitmasksconstructive-algorithmshashing
CF 1905C - Largest Subsequence

We are given a string of lowercase English letters, and our goal is to transform it into a non-decreasing sorted string using a specific operation.

codeforcescompetitive-programminggreedystrings
CF 1905E - One-X

We are asked to work with a segment tree built over an array of length $n$, where the segment tree is the standard binary recursive construction. Each node of the tree corresponds to a segment of the array, and the root node is labeled $1$.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpmathtrees
CF 1905B - Begginer's Zelda

We are given a tree and a special operation. In one operation, we choose any two vertices and look at the unique path between them. Every vertex on that path is merged into a single new vertex.

codeforcescompetitive-programminggreedytrees
CF 1905D - Cyclic MEX

We are given a permutation of numbers from 0 to n−1. We are allowed to rotate this array cyclically, and for each possible rotation we compute a score as we scan from left to right.

codeforcescompetitive-programmingdata-structuresimplementationmathtwo-pointers
CF 1894A - Secret Sport

We observe a sequence of match outcomes where each character represents a single play won by either player A or player B. These plays are grouped into sets: a set ends as soon as one player accumulates $X$ wins inside that set.

codeforcescompetitive-programmingimplementationstrings
CF 1894E - Freedom of Choice

Working

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementation
CF 1894D - Neutral Tonality

We are given two sequences. The first sequence is already fixed in its internal order, and we are not allowed to reorder it.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuressortingstwo-pointers
CF 1894B - Two Out of Three

We are given an array of integers and need to construct a parallel array of labels containing only 1, 2, or 3. The goal is to satisfy exactly two out of three pairing conditions, each involving two indices where the original numbers are equal and the assigned labels form one…

codeforcescompetitive-programmingconstructive-algorithms
CF 1894C - Anonymous Informant

We are given an array $b$ of length $n$ and a number $k$, which represents the number of operations performed on some hidden original array $a$. Each operation consists of choosing a fixed point $x$ in $a$ and cyclically left-shifting $a$ by $x$ positions.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 1890E2 - Doremy's Drying Plan (Hard Version)

We have $n$ cities arranged along a line and a forecast of rain for $m$ consecutive days. Each day's rain covers a continuous interval of cities $[li, ri]$. A city is dry if it never experiences rain across all $m$ days.

codeforcescompetitive-programmingdata-structuresdp
CF 1890E1 - Doremy's Drying Plan (Easy Version)

We are given a sequence of cities numbered from 1 to $n$ and a forecast of rain for the next $m$ days. On day $i$, rain will cover the cities in the interval $[li, ri]$. A city is dry if no rain ever falls there during the $m$ days. Doremy can prevent rain on exactly two days.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 1890F - Game of Stacks

Each stack belongs to a vertex. If we are currently at vertex u, we look at the top element of stack u. If the stack is empty, the process stops and returns u. Otherwise we pop the top element, jump to the vertex written on that element, and repeat.

codeforcescompetitive-programmingdfs-and-similargraphsimplementationtrees
CF 1890B - Qingshan Loves Strings

We are given two binary strings, s and t. Qingshan wants to transform s into a string where no two consecutive characters are the same, called a "good" string. She can repeatedly insert string t anywhere in s, including at the start or end, any number of times.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1890C - Qingshan Loves Strings 2

We are given a binary string consisting only of 0s and 1s. The task is to transform it into a string that satisfies the following "good" property: for every position i in the string, the character at i must differ from the character at the symmetric position counted from the…

codeforcescompetitive-programmingconstructive-algorithmsimplementationtwo-pointers
CF 1877F - Lexichromatography

We are asked to count the number of ways to colour an array of integers either blue or red, subject to two constraints.

codeforcescompetitive-programmingcombinatoricsdsu
CF 1877G - Ball-Stackable

We are given a tree where some edges already have a fixed direction and some edges are still undirected. We must choose directions for the remaining edges and assign a color to every edge. A walk may traverse an edge either along its direction or against it.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdptrees
CF 1877E - Autosynthesis

We are given a sequence of positive integers indexed from left to right. We are allowed to repeatedly choose positions and “circle” elements. The key twist is that circling does not remove elements immediately; it only marks them.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 1877C - Joyboard

We choose a value $a{n+1}$ between $0$ and $m$. After that, every earlier position is determined uniquely by $$ai = a{i+1} bmod i$$ for $i=n,n-1,dots,1$. The entire array is generated from a single starting value.

codeforcescompetitive-programmingmathnumber-theory
CF 1877D - Effects of Anti Pimples

We are given an array indexed from 1 to n. We repeatedly choose a non-empty subset of indices and mark them as special. Those chosen indices are colored black. After that, any still-unselected index becomes green if it is a multiple of at least one black index.

codeforcescompetitive-programmingcombinatoricsnumber-theorysortings
CF 1877B - Helmets in Night Light

We are tasked with spreading an announcement to all residents of a village in the cheapest way possible. There are two ways to inform residents: Pak Chanek can directly tell someone at a fixed cost p, or a resident who already knows can inform others using a magical helmet…

codeforcescompetitive-programmingbinary-searchgreedysortings
CF 1875C - Jellyfish and Green Apple

We are given a collection of green apple pieces, each weighing exactly 1 kilogram. The goal is to distribute these pieces among a fixed number of people so that each person ends up with the same total weight.

codeforcescompetitive-programmingbitmasksgreedymathnumber-theory
CF 1875F - Jellyfish and EVA

The solution correctly restates the exercise in terms of the frequency test and the chi-square statistic for $b$ categories. It identifies the expected value $E(chi^2)=b-1$ and explains why the observed value $1.06$ for the first 2000 decimal digits is unusually small.

codeforcescompetitive-programmingdpgraphsgreedymathprobabilities
CF 1875A - Jellyfish and Undertale

We are asked to maximize the time until a bomb explodes. The bomb has a timer b initially, which decreases by 1 every second. You have n tools, each capable of increasing the timer by xi when used, but the timer cannot exceed a maximum value a.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1875E - Jellyfish and Math

Codeforces 1875E: Jellyfish and Math

codeforcescompetitive-programmingbitmasksdfs-and-similardpgraphs
CF 1875D - Jellyfish and Mex

We are given an array of nonnegative integers. The task is to remove elements from the array one by one, and after each removal, we add the MEX of the remaining array to a running total. The goal is to minimize this total by choosing the deletion order optimally.

codeforcescompetitive-programmingdp
CF 1875B - Jellyfish and Game

We are asked to simulate a turn-based exchange game between two players, Jellyfish and Gellyfish. Jellyfish owns an array of apples with integer values, and Gellyfish owns a different array.

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1869E - Travel Plan

We are asked to consider a country with $n$ cities connected in a tree-like structure that mirrors a complete binary tree. Each city $i$ has edges to $2i$ and $2i+1$ if those indices do not exceed $n$.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1869F - Flower-like Pseudotree

This problem is a Codeforces 3000-rated constructive graph problem. Producing a correct editorial requires reconstructing and proving the entire degree-sequence characterization of flower-like pseudotrees, together with the linear-time construction used in the official solution.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementationtrees
CF 1869D2 - Candy Party (Hard Version)

We have a party with n people, each bringing a certain number of candies. Each person can give exactly a power-of-two number of candies to another person, and every person can give to at most one person and receive from at most one person.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedyimplementationmath
CF 1869A - Make It Zero

For Codeforces 1869A, the entire solution is a constructive observation. If n is even, perform: After the first operation, every element becomes X, where X is the XOR of the whole array.

codeforcescompetitive-programmingconstructive-algorithms
CF 1869C - Fill in the Matrix

We are asked to construct an $n times m$ matrix where every row is a permutation of the numbers from $0$ to $m-1$. This means each row contains all values exactly once, but rows can differ from each other. Once the matrix is built, each column induces a multiset of $n$ values.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1869D1 - Candy Party (Easy Version)

We have a party with n people, each holding a certain number of candies ai. Each person will give a positive number of candies to exactly one other person, and each person will receive candies from exactly one other person.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgraphsimplementationmath
CF 1862G - The Great Equalizer

The problem presents a magical device called "The Great Equalizer" which takes an array of integers and repeatedly applies a transformation.

codeforcescompetitive-programmingbinary-searchdata-structuresmathsortings
CF 1862D - Ice Cream Balls

We are asked to determine the minimum number of ice cream balls Tema needs to buy to make exactly n distinct two-ball ice cream cones. Each cone consists of two balls, which may be of the same flavor.

codeforcescompetitive-programmingbinary-searchcombinatoricsconstructive-algorithmsmath
CF 1862B - Sequence Game

We are asked to reconstruct a possible original sequence a given a sequence b that was derived by a simple filtering rule. The sequence b always starts with the first element of a, and then includes every element of a that is greater than or equal to its immediate predecessor.

codeforcescompetitive-programmingconstructive-algorithms
CF 1862A - Gift Carpet

We are given a rectangular carpet of size $n times m$ where each cell contains a lowercase letter. Vika likes to read her name "vika" from the carpet by selecting one letter from each column, moving strictly left to right, and choosing exactly four columns for the letters 'v'…

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 1857G - Counting Graphs

We are given a tree on $n$ vertices, where each edge has an integer weight. The task is to count the number of weighted simple graphs such that the given tree is the unique minimum spanning tree (MST), and all edge weights in the graph are integers not exceeding $S$.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdsugraphsgreedysortingstrees
CF 1857F - Sum and Product

The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.

codeforcescompetitive-programmingbinary-searchdata-structuresmath
CF 1857E - Power of Points

We are given several test cases. In each test case, we start with a list of points placed on a number line. For every point we choose one special position s, and we connect s to every point xi by a segment on the integer line.

codeforcescompetitive-programmingmathsortings
CF 1857D - Strong Vertices

We are given two arrays, a and b, both of length n. From these arrays, we are asked to construct a directed graph with n vertices. There is an edge from vertex u to vertex v (for u != v) if the difference a[u] - a[v] is greater than or equal to b[u] - b[v].

codeforcescompetitive-programmingmathsortingstrees
CF 1857C - Assembly via Minimums

The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.

codeforcescompetitive-programminggreedysortings
CF 1857B - Maximum Rounding

We are given a number written as a string of digits, and we are allowed to repeatedly apply a specific rounding operation that changes digits at a chosen position and propagates carry to higher positions in a non-standard way.

codeforcescompetitive-programminggreedyimplementationmath
CF 1857A - Array Coloring

We are given an array of integers and need to decide whether it can be partitioned into two non-empty groups such that the sums of each group have the same parity-both even or both odd. Each group must contain at least one element.

codeforcescompetitive-programminggreedymath
CF 1858B - The Walkway

Petya walks past benches numbered from 1 to n. Some benches contain cookie sellers. Whenever Petya reaches a bench, he eats a cookie if one of three things is true: 1. The bench contains a seller, in which case he immediately buys and eats a cookie. 2. He has never eaten before.

codeforcescompetitive-programmingbrute-forcedpgreedymathnumber-theory
CF 1858D - Trees and Segments

We are given a binary string representing a row of trees, where each position is either an oak or a fir. The quality of a final arrangement depends only on two numbers: the longest consecutive block of zeros and the longest consecutive block of ones.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedytwo-pointers
CF 1858E2 - Rollbacks (Hard Version)

We are asked to maintain a dynamic array while processing four types of queries: append a number, remove the last $k$ numbers, roll back the last change (append or remove), and report the number of distinct numbers in the array. The array is initially empty.

codeforcescompetitive-programmingdata-structuresinteractivetrees
CF 1858E1 - Rollbacks (Easy Version)

We are asked to maintain an array under four types of operations: appending an element, removing the last $k$ elements, rolling back the last change (which could be either an append or a removal), and querying the number of distinct elements currently in the array.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similartrees
CF 1858C - Yet Another Permutation Problem

We are asked to construct permutations of integers from 1 to $n$ in such a way that, when we compute the greatest common divisor (GCD) between consecutive elements (with wrap-around), the number of distinct GCD values is maximized.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1858A - Buttons

Two players alternate turns removing objects from a shared pool. Each object is a “button” with a restriction: some buttons can only be taken by Anna, some only by Katie, and some are flexible and can be taken by either player.

codeforcescompetitive-programminggamesgreedymath
Kvant Math Problem 1551

A closed broken line with six segments is a hexagonal cycle whose six vertices lie on one circle.

kvantmathematicsolympiad
CF 1859E - Maximum Monogonosity

We are given two arrays of length $n$, $a$ and $b$. For any contiguous subarray, or segment, defined by its start $l$ and end $r$, we can compute a "cost" using the formula $ The problem is subtle because segment costs depend on both ends of the segment and both arrays.

codeforcescompetitive-programmingbrute-forcedpmath
CF 1859D - Andrey and Escape from Capygrad

We are asked to model escape paths in a one-dimensional world where Andrey can use portals repeatedly. Each portal is a segment [li, ri] from which Andrey can enter and teleport to another contained segment [ai, bi].

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsugreedysortings
CF 1859F - Teleportation in Byteland

We are given a tree with n cities connected by roads. Each road has a hardness value wi. The travel time along a road depends on the driver’s skill c and is calculated as ceil(wi / c).

codeforcescompetitive-programmingdata-structuresdfs-and-similardivide-and-conquergraphsshortest-pathstrees
CF 1859C - Another Permutation Problem

We are given a permutation of the numbers from 1 to n. For a permutation p, define $$text{cost}(p)=sum{i=1}^{n} pi cdot i-max{i=1}^{n}(picdot i).$$ The task is to find the largest possible value of this expression among all permutations of length n.

codeforcescompetitive-programmingbrute-forcedpgreedymath
CF 1859B - Olya and Game with Arrays

We are given multiple arrays, each containing at least two positive integers. We are allowed to move at most one number from each array to some other array. After these moves, the “beauty” of the collection is defined as the sum of the smallest element in each array.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathsortings
CF 1859A - United We Stand

We are given an array of integers, and our goal is to split it into two non-empty arrays, b and c, such that no element in c divides any element in b. Each element must go into exactly one array. If this is impossible, we return -1.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1860E - Fast Travel Text Editor

We are given a string and a cursor that initially sits between two letters. The cursor can move left or right by one position, and it can also "teleport" between any two adjacent letters x and y if there exists another pair x followed by y elsewhere in the string.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsshortest-paths
CF 1860F - Evaluate RBS

We are given $2n$ tuples of the form $(a, b, c)$, where $a$ and $b$ are positive integers and $c$ is a bracket, either '(' or ')'. Exactly half of the tuples are opening brackets and the other half are closing brackets.

codeforcescompetitive-programmingdata-structuresgeometryimplementationmathsortings
CF 1860D - Balanced String

We are given a binary string, and we are allowed to reorder it using swaps between any two positions. The cost of each operation is one swap, and swaps are unrestricted in the sense that we can choose any pair of indices.

codeforcescompetitive-programmingdp
CF 1860A - Not a Substring

We are given a string s consisting only of parentheses, and we need to construct a new string t of length exactly twice that of s, such that t forms a valid bracket sequence and s does not appear anywhere inside t as a contiguous substring.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1860C - Game on Permutation

We are given a permutation and a game played on its positions. The chip starts nowhere. Alice begins by choosing any position and placing the chip there. After that, players alternate moving the chip.

codeforcescompetitive-programmingdata-structuresdpgamesgreedy
CF 1860B - Fancy Coins

We are asked to determine the minimum number of fancy coins Monocarp must use to pay exactly m burles when he has two types of coins: one worth 1 burle and one worth k burles.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1861F - Four Suits

In this problem, we have a card game with multiple players and a dealer. Each card belongs to one of four suits. The dealer has already partially dealt cards to players, and some cards remain in the deck.

codeforcescompetitive-programmingbinary-searchbitmasksflowsgreedy
CF 1861E - Non-Intersecting Subpermutations

We are asked to consider arrays of length n filled with integers from 1 to k. The "cost" of an array is defined as the maximum number of contiguous subarrays of length exactly k where each subarray contains all integers from 1 to k exactly once, and no element participates in…

codeforcescompetitive-programmingcombinatoricsdpimplementationmath
CF 1861D - Sorting By Multiplication

We are given an array of positive integers, and our task is to transform it into a strictly increasing sequence using the fewest operations.

codeforcescompetitive-programmingdpgreedy
CF 1861C - Queries for the Array

We are asked to check whether a given sequence of symbols could have been produced by operations on an array that starts empty.

codeforcescompetitive-programmingdata-structuresdfs-and-similarimplementationstringstrees
CF 1861B - Two Binary Strings

We are given two binary strings of equal length. Both strings always start with a 0 and end with a 1. We are allowed to repeatedly apply an operation that takes a segment inside one string, provided the endpoints of that segment contain the same character, and then forces…

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1861A - Prime Deletion

We start with a fixed multiset of digits from 1 to 9, each appearing exactly once, written in a row. The only operation allowed is deleting digits one by one, with the restriction that we are not allowed to delete when only two digits remain in the current sequence.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1862F - Magic Will Save the World

We are asked to calculate the minimum time Vika, a sorceress, needs to defeat a sequence of monsters. Each monster has a strength, and Vika has two types of magic-water and fire. In one second, she generates fixed amounts of water and fire mana.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedp
CF 1862E - Kolya and Movie Theatre

Kolya wants to visit a movie theatre over n consecutive days, each day showing a new movie. Each movie has a raw entertainment value a[i], but the enjoyment Kolya actually gains is reduced by how long he has waited since his last visit.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1862C - Flower City Fence

We are given a sequence of fence planks, each with a height, already sorted in non-increasing order. Anya wants to know if the fence is symmetrical when viewed as a grid of unit blocks.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationsortings
CF 1863I - Redundant Routes

We are given a tree, so between any two vertices there is exactly one simple path. From this tree we want to choose several distinct vertex-sets, where each chosen set must itself be the vertex set of some simple path that contains at least two vertices.

codeforcescompetitive-programmingconstructive-algorithmsdptrees