brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 2183A - Binary Array Game

We are given a binary array that evolves through a merging game. Two players, Alice and Bob, alternate turns. On each turn, a player selects a contiguous segment of length at least two, removes it, and replaces it with a single value derived from that segment.

codeforcescompetitive-programminggames
CF 2184F - Cherry Tree

We have a rooted tree whose leaves each contain exactly one cherry. A shake performed at vertex v makes the cherries fall from every leaf inside the subtree of v. Once a cherry has fallen, it must never be affected by another shake.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 2184G - Nastiness of Segments

We are given an array of integers placed on a line, and we must support two operations: point updates and range queries. The interesting part is not the update itself, but how a special property behaves over a segment.

codeforcescompetitive-programmingbinary-searchdata-structures
CF 2184D - Unfair Game

Working

codeforcescompetitive-programmingcombinatoricsdpmath
CF 2184E - Exquisite Array

We are given a permutation of length $n$, which is simply an array of integers from $1$ to $n$ in some order without repeats.

codeforcescompetitive-programmingcombinatoricsdata-structuresdsusortings
CF 2184B - Hourglass

Vadim has an hourglass that measures exactly s minutes. He flips it initially, and after every k minutes, he flips it again, regardless of whether all the sand has fallen. If the sand finishes before the next flip, he waits until the scheduled flip time.

codeforcescompetitive-programmingmath
CF 2184A - Social Experiment

We have $n$ people. They must be partitioned into teams, where every team has either 2 or 3 members. After the teams are formed, each team independently chooses one of two civilizations.

codeforcescompetitive-programmingmath
CF 2184C - Huge Pile

Andrei starts with a single pile containing $n$ apples. He can split any pile of size $x$ into two smaller piles in exactly one minute, creating one pile of $lfloor x/2 rfloor$ apples and another of $lceil x/2 rceil$ apples.

codeforcescompetitive-programmingbinary-searchdfs-and-similardpgraphsmath
CF 2185H - BattleCows 2

The tournament has a surprisingly simple structure once we stop thinking about individual matches. Whenever a cow survives a match, its new skill becomes the sum of the two participants.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpgreedy
CF 2185G - Mixing MEXes

We are given multiple arrays and are allowed to perform a single operation: choose an element from one array, move it to the end of another array, and then compute the sum of MEXes of all arrays after this move. The task is to sum the values of all possible such operations.

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 2185F - BattleCows

The tournament can be viewed as a complete binary tree over the array of cows. Each leaf is a single cow. Every internal node represents a contiguous segment of cows. The skill of a node is the XOR of all values inside that segment.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerimplementation
CF 2185E - The Robotic Rush

Every robot receives exactly the same sequence of moves. After the first instruction, all robots shift by the same displacement. After the second instruction, all robots shift by another common displacement, and so on.

codeforcescompetitive-programmingbinary-searchgreedyimplementationtwo-pointers
CF 2185D - OutOfMemoryError

We start with an array and a sequence of update operations. Each operation adds some value to one position. The unusual part is the crash rule. After every update, if any element of the current array becomes larger than h, the computer immediately crashes.

codeforcescompetitive-programmingdata-structuresimplementationmathtwo-pointers
CF 2185C - Shifted MEX

We are given an array of integers, which may include negative numbers. The task allows us to pick a single integer shift x and add it to every element of the array. After performing this shift, we want to maximize the MEX of the array.

codeforcescompetitive-programmingimplementationsortings
CF 2185A - Perfect Root

We are asked to generate a sequence of distinct "perfect roots" for each test case. A perfect root is simply an integer $x$ such that $x^2$ is also an integer, which is trivially true for all positive integers.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2185B - Prefix Max

We are given an array. For every position, we look at the prefix ending there and take the maximum value seen so far. The score of the array is the sum of all those prefix maxima. We may swap any two elements at most once, or choose not to swap at all.

codeforcescompetitive-programminggreedy
CF 2187G - Many Cartesian Trees

We are asked to reconstruct a permutation $q$ of length $n$ from a special encoding of Cartesian trees derived from a series of arrays.

codeforcescompetitive-programminggreedysortingstrees
CF 2187F1 - Al Fine (Maximizing Version)

We are given two DFS preorder traversals of the same set of vertices {0,1,...,n}. The tree itself is unknown. The only thing we know is that in both traversals the root 0 appears first, and for every vertex the order of its children during DFS is arbitrary.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquertrees
CF 2187F2 - Al Fine (Counting Version)

I can write the editorial, but only if I can first reconstruct the solution completely and verify the algorithm. For this particular problem, the official editorial for F2 is unusually terse and omits many crucial details.

codeforcescompetitive-programmingdptrees
CF 2187E - Doors and Keys

We have a sequence of $n+1$ rooms connected by $n$ doors. Each door $i$ has a number $ai$ indicating the exact second it will automatically open, if untouched. Some rooms contain keys at the start according to a binary string $s$, where a 1 means a key exists in that room.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 2187A - Restricted Sorting

We are given an array of integers, and we are asked to determine the largest integer $k$ such that we can sort the array in non-descending order by swapping any two elements whose difference is at least $k$.

codeforcescompetitive-programminggreedysortings
CF 2187C - Jerry and Tom

We are asked to analyze a two-player game on a directed graph with $n$ vertices. The graph is almost a chain: for every vertex $u$ from 1 to $n-1$, there is an edge $u to u+1$.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugamesgraphsgreedytrees
CF 2188B - Seats

We are given a row of seats represented as a binary string, where 1 indicates a student is sitting there and 0 indicates an empty seat. No two students are adjacent initially.

codeforcescompetitive-programminggreedy
CF 2189F - Zhora the Vacuum Cleaner

We have a tree. Vertex i initially contains ai nuts. There are two kinds of electricity costs. The first cost comes from a special redistribution operation. We choose a vertex v. Then every other vertex is processed from larger distance to smaller distance from v.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpgreedyimplementationsortingstrees
CF 2189D2 - Little String (Hard Version)

We are not asked to count permutations directly. The real task is to understand which binary strings $w$ are possible, what value $f(w)$ they produce, and then optimize over all replacements of the question marks.

codeforcescompetitive-programmingcombinatoricsdpgreedymathnumber-theory
CF 2189E - Majority Wins?

We are given a binary string s of length n. Our goal is to transform this string into a single character "1" using a special operation: we can take any contiguous substring, and replace it with the character that occurs at least as many times as the other character in that…

codeforcescompetitive-programmingconstructive-algorithmsgreedymathstrings
CF 2189D1 - Little String (Easy Version)

We are given a string of length $n$ consisting of 0s and 1s. For a permutation $p$ of $[0, 1, dots, n-1]$, the function $f(w)$ counts the number of permutations such that, for each position $i$, the minimum excluded value (MEX) condition is satisfied: if $wi = 1$, there exists…

codeforcescompetitive-programmingcombinatoricsdpgreedymathnumber-theory
CF 2189A - Table with Numbers

We have an array of numbers. We may select any even number of elements from it and partition them into ordered pairs. A pair (x, y) contributes 1 to the table only if row x and column y exist.

codeforcescompetitive-programminggreedyimplementation
CF 2189C1 - XOR Convenience (Easy Version)

We need to construct a permutation of the numbers from 1 to n. For every position i with 2 ≤ i ≤ n-1, there must exist some position j satisfying i ≤ j ≤ n such that $$pi = pj oplus i.$$ Since we are free to choose the entire permutation, this is a constructive problem.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmath
CF 2189B - The Curse of the Frog

We are asked to help a frog move along an infinite number line from position 0 to a target position $x$. The frog has $n$ types of magical jumps.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 2190G - Maximize Determinant

I can't reliably write a complete accepted editorial and proof for Codeforces 2190G from the problem statement alone.

codeforcescompetitive-programminggraphs
CF 2190D - Prufer Vertex

We start with a forest. We may add edges between its connected components until the whole graph becomes a single tree. For every resulting tree, run the standard Prüfer-code deletion process: repeatedly remove the smallest numbered leaf until only two vertices remain.

codeforcescompetitive-programmingcombinatoricsdsunumber-theoryprobabilitiestrees
CF 2190E - Median Permutation

Instead of thinking about medians directly, it is much more useful to think about the permutation being revealed in increasing value order. Suppose we process the values of a permutation from 1 to n. When value x is processed, its position becomes "active".

codeforcescompetitive-programmingcombinatorics
CF 2190F - Xor Product

The official editorial for this problem is exceptionally long and derives a fairly intricate bit-DP from several structural lemmas about XOR products of intervals.

codeforcescompetitive-programmingbitmasksdp
CF 2190C - Comparable Permutations

We are asked to interact with a hidden permutation p of size n and produce a permutation q that is lexicographically just larger than p and also satisfies the property that reversing q gives a permutation larger than the reverse of p. The catch is that we never see p directly.

codeforcescompetitive-programminggreedyimplementationinteractivesortingstwo-pointers
CF 2190B2 - Sub-RBS (Hard Version)

We are asked to compute a sum over all non-empty subsequences of a given bracket sequence. Each subsequence has a “score” defined as the length of its longest regular bracket subsequence that is strictly “better” than itself.

codeforcescompetitive-programmingdpgamesimplementationstrings
CF 2190B1 - Sub-RBS (Easy Version)

We are given a regular bracket sequence s. A regular bracket sequence (RBS) is one where every prefix contains at least as many '(' as ')', and the total numbers of opening and closing brackets are equal.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpgreedystringstwo-pointers
CF 2190A - Sorting Game

We are asked to analyze a two-player game on a binary string, where Alice goes first and Bob follows, taking turns. On their turn, a player may select any strictly non-increasing subsequence of the string and rearrange it to be non-decreasing.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 2191A - Array Coloring

We are asked to color a sequence of distinct integers arranged in a row using two colors so that two conditions hold simultaneously. First, any two adjacent numbers in the original sequence must have different colors.

codeforcescompetitive-programmingconstructive-algorithms
CF 2192E - Swap to Rearrange

Each position i contains a pair of values (ai, bi). For that position we have exactly two choices. If we do nothing, the value ai stays in array a and bi stays in array b. If we swap that position, the value bi moves to array a and ai moves to array b.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraph-matchingsgraphsgreedystrings
CF 2192D - Cost of Tree

We are given a tree rooted at node 1, where each node carries a positive integer weight. The cost of the tree, relative to a chosen root, is the sum over all nodes of the product of the node's weight and its distance from that root.

codeforcescompetitive-programmingdpgreedytrees
CF 2192F - Fish Fight

I can write a full editorial only if I first reconstruct the actual solution in detail. For this problem, the official editorial contains a fairly intricate two-phase DP with interval states, probability propagation, prefix/suffix aggregation, and a second DP once the two…

codeforcescompetitive-programmingdpmathprobabilities
CF 2192B - Flipping Binary String

We are given a binary string, which is a sequence of 0s and 1s, and we can perform a very specific operation: pick one index i, and flip every bit in the string except the bit at index i. Flipping means changing 0 to 1 and 1 to 0.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 2192C - All-in-one Gun

We are given a shooter game scenario where we have a gun with a magazine of n bullets. Each bullet has a fixed damage ai, and bullets are fired in sequence, one per second.

codeforcescompetitive-programmingbinary-searchgreedymath
CF 2192A - String Rotation Game

We are given a string consisting of lowercase letters and asked to determine how to rotate it to maximize the number of contiguous blocks of identical letters. A block is defined as a maximal substring of consecutive identical characters.

codeforcescompetitive-programmingbrute-forcestrings
CF 2193H - Remove the Grail Tree

We are given a tree, which is a connected acyclic graph with $n$ vertices, and each vertex has an associated integer value. The operation we can perform repeatedly is to remove a vertex if the sum of the values of its remaining neighbors differs in parity from its own value.

codeforcescompetitive-programmingdfs-and-similardpgraphsgreedyimplementationtrees
CF 2193G - Paths in a Tree

We are given a tree, which is an undirected, connected, acyclic graph of $n$ vertices. Two hidden vertices, $x$ and $y$, define a unique path because trees have exactly one simple path between any pair of vertices.

codeforcescompetitive-programmingdfs-and-similarinteractivesortingstrees
CF 2193F - Pizza Delivery

The courier starts at $(Ax, Ay)$, must visit every house, and finally reach $(Bx, By)$. The movement rules are unusual. He may move one unit to the right, one unit up, or one unit down. He can never decrease his $x$-coordinate.

codeforcescompetitive-programmingdpgreedy
CF 2193E - Product Queries

We are given an array whose values lie between 1 and n. An element may be reused any number of times, so the only thing that matters is which values are present in the array, not how many times they occur.

codeforcescompetitive-programmingdpmathnumber-theoryshortest-paths
CF 2193D - Monster Game

We are given a sequence of swords, each having a strength value, and a sequence of monsters, each requiring a certain number of strikes to be defeated. Each sword can be used at most once, because after striking a monster it breaks immediately.

codeforcescompetitive-programmingbinary-searchsortingstwo-pointers
CF 2193C - Replace and Sum

We start with two arrays of the same length. For any position, we may directly overwrite a[i] with b[i]. We may also copy values from right to left by replacing a[i] with the current value of a[i+1]. Each query asks for the largest possible sum on a subarray a[l..

codeforcescompetitive-programmingdata-structuresgreedy
CF 2193B - Reverse a Permutation

We are given a permutation of numbers from 1 to n, which means every number in this range appears exactly once. We are allowed to choose a single continuous segment of this permutation and reverse it.

codeforcescompetitive-programminggreedy
CF 2193A - DBMB and the Array

We are given an array of integers and a fixed increment value. In one move, we can pick any position in the array and increase that single element by exactly the same amount each time. We can repeat this operation as many times as we want on any indices.

codeforcescompetitive-programmingbrute-forcemath
CF 2194F2 - Again Trees... (hard version)

We are asked to count certain ways to cut a tree into connected components with a specific property. The tree has n vertices, each with a value av. We are also given a small set of numbers b1, ..., bk.

codeforcescompetitive-programmingbitmasksdata-structuresdfs-and-similardpffttrees
CF 2194E - The Turtle Strikes Back

We have a rectangular grid. Every cell contains an integer value, positive or negative. Michelangelo chooses a path from the top-left corner to the bottom-right corner. He may only move right or down.

codeforcescompetitive-programmingdpgraphsgreedyimplementation
CF 2194D - Table Cut

We are given a grid of size $n times m$ filled with zeros and ones. We need to make a cut from the top-left corner to the bottom-right corner, moving only right or down.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 2194F1 - Again Trees... (Easy Version)

We are given a tree with n vertices, where each vertex has a non-negative integer av written on it. We are also given a set of k distinct non-negative integers b1, ..., bk.

codeforcescompetitive-programmingbitmasksdfs-and-similardptrees
CF 2194B - Offshores

We are given several independent scenarios. In each scenario, there are multiple bank accounts, each holding some amount of money.

codeforcescompetitive-programminggreedyimplementationmath
CF 2194C - Secret message

We are given multiple strips of paper, each of the same length, containing lowercase letters. Each column across the strips represents a choice: the letter at that column in the decrypted message must come from one of the letters in that column of the strips.

codeforcescompetitive-programmingbitmasksbrute-forcedpmathnumber-theory
CF 2194A - Lawn Mower

We are given a fence made of $n$ unit-width boards arranged in a line. We are allowed to remove any subset of these boards, but doing so creates gaps in the fence. The only constraint is that the removed boards must not form a continuous block of length $w$ or more.

codeforcescompetitive-programminggreedymath
CF 2195H - Codeforces Heuristic Contest 001

We are given a square grid of points with coordinates from 1 to 3n along both axes, forming a total of $3n times 3n$ points. The task is to select the largest possible set of triangles such that each triangle uses three distinct points from the grid, has an area of exactly 0.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometryimplementation
CF 2195G - Idiot First Search and Queries

We are given a rooted binary tree where every vertex either has exactly two children or is a leaf. The root is vertex 0, and all other vertices are numbered from 1 to n. A process starts from some vertex v and moves step by step according to a very specific stateful rule.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgraphstrees
CF 2195F - Parabola Independence

We are given a set of quadratic functions, each defined by coefficients $ai$, $bi$, and $ci$. Two functions are called independent if they never intersect, which algebraically means their difference is never zero.

codeforcescompetitive-programmingdpgraphsgreedymathsortings
CF 2195E - Idiot First Search

We are given a rooted binary tree where vertex 0 is the root and every other vertex is either a leaf or has exactly two children, left and right. The vertices are numbered, and the structure is fully specified by child pointers.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 2195D - Absolute Cinema

We are given a hidden sequence of integers $a1, a2, dots, an$ and, instead of the sequence itself, we are provided with a function evaluated at each index: $f(x) = sum{i=1}^n ai cdot Given that $n$ can be as large as 300,000 and the total sum over all test cases is also…

codeforcescompetitive-programmingmath
CF 2195B - Heapify 1

We are given a permutation of integers from 1 to n and can perform a specific type of swap: for any index i from 1 to n/2, we can swap the element at position i with the element at position 2i.

codeforcescompetitive-programmingimplementationsortings
CF 2195C - Dice Roll Sequence

We are given a sequence of numbers from 1 to 6, and we are allowed to change any element to any other value from 1 to 6. The goal is to transform the sequence so that every pair of neighboring elements behaves like valid transitions on a standard dice.

codeforcescompetitive-programmingdpgreedy
CF 2195A - Sieve of Erato67henes

We are given several very small collections of integers, each collection containing at most five numbers, and we are asked whether we can pick some non-empty subset whose product is exactly 67. Each test case is independent.

codeforcescompetitive-programmingmathnumber-theory
CF 2196F - Indivisible

We are asked to construct a graph with a given number of vertices n and edges m such that it cannot be split into two parts where the sums of degrees of each part are equal. The graph must be simple, with no loops or multiple edges.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgraphs
CF 2196E2 - Fuzzy Concatenation (Hard version)

We are given a source string s and a target string t. We start with an empty string p and want to build it until it becomes exactly equal to t.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdpgreedystring-suffix-structures
CF 2196E1 - Fuzzy Concatenation (Easy Version)

We are given a source string s and a target string t. We start with an empty string p, and our only goal is to build p until it exactly matches t.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedata-structuresgreedystring-suffix-structures
CF 2196D - Double Bracket Sequence

We are given a string consisting of round brackets "(" and ")", and square brackets "[" and "]". The string has even length.

codeforcescompetitive-programmingdata-structuresdpexpression-parsingflowsgreedystrings
CF 2196C2 - Interactive Graph (Hard Version)

We are asked to reconstruct a hidden directed acyclic graph (DAG) by interacting with a system that enumerates all paths in lexicographic order. Each query allows us to ask for the $k$-th path.

codeforcescompetitive-programmingcombinatoricsdfs-and-similardpgraphsinteractive
CF 2196A - Game with a Fraction

We are given two integers, $p$ and $q$, representing a fraction $frac{p}{q}$. Alice and Bob play a turn-based game where on each turn a player can decrease $p$ by 1 (if $p 0$) or decrease $q$ by 1 (if $q 1$). Alice goes first.

codeforcescompetitive-programminggamesmath
CF 2196C1 - Interactive Graph (Simple Version)

We are given a directed acyclic graph with up to 15 vertices. The edges are unknown, but we are allowed to probe the graph through an oracle. Each query asks for the k-th path in the lexicographically sorted list of all valid directed paths in the graph.

codeforcescompetitive-programmingbinary-searchcombinatoricsdfs-and-similardpgraphsinteractive
CF 2196B - Another Problem about Beautiful Pairs

We are given an array and we want to count pairs of positions where a very specific relationship holds between the values at those positions and their distance in the array.

codeforcescompetitive-programmingbrute-forcemathtwo-pointers
CF 2197A - Friendly Numbers

We are given an integer $x$, and we want to count how many integers $y$ satisfy a very specific balancing condition: if you take $y$ and subtract the sum of its digits, you land exactly on $x$.

codeforcescompetitive-programmingbinary-searchbrute-forceexpression-parsingmathschedules
CF 2199I - Strange Process

We start with a very constrained system: one array begins as all ones, another array is all zeros, and a third array c provides a sequence of target values between 1 and 50.

codeforcescompetitive-programming*special
CF 2199H - Sum of MEX

We are given an array of length $n$ where each element is an integer from $-1$ to $n$. The special value $-1$ is a wildcard that can be replaced by any integer between $0$ and $n$.

codeforcescompetitive-programming*specialcombinatoricsdata-structuresdpmath
CF 2199F - Self-Produced Sequences

We are given an integer array and asked to count subsequences that are "self-produced." A sequence is self-produced if for every element, either the sum of all previous elements equals that element, or the sum of all following elements equals that element.

codeforcescompetitive-programming*specialcombinatoricsmath
CF 2199G - Jammer

We are asked to find positions on a rectangular grid where we can place a jammer such that it always intercepts a robot moving from the bottom-left corner $(0,0)$ to the top-right corner $(n,m)$, while remaining invisible at the start and end points.

codeforcescompetitive-programming*specialmath
CF 2199E - Supersequence

We are given an initial array $a$, and we want to imagine building a longer array $b$ that contains all elements of $a$ in order (not necessarily consecutively), but between every pair of adjacent elements in $b$, the values must differ by exactly 1.

codeforcescompetitive-programming*specialbinary-searchgreedy
CF 2199A - Game

Alice and Bob play a three-round card game where each round has independent scores between 0 and a maximum k. The first two rounds are already played, with Alice and Bob scoring a1, b1 in round one and a2, b2 in round two.

codeforcescompetitive-programming*special
CF 2199D - Two Arrays

We are given two arrays, each sorted in non-decreasing order, and each having an odd number of elements. The task is to determine whether we can make the two arrays identical using a sequence of operations.

codeforcescompetitive-programming*specialmath
CF 2199C - Minesweeper

We are asked to build a grid with exactly two rows and some number of columns. Each cell can either contain a mine or be empty.

codeforcescompetitive-programming*specialconstructive-algorithmsgreedy
CF 2199B - Two Towers

We start with two stacks of blocks. The first stack has height a, the second has height b. We want to reach target heights c and d respectively, only by increasing heights. There are two allowed operations. The first operation increases exactly one of the towers by one block.

codeforcescompetitive-programming*specialgreedymath
CF 2200H - Six Seven

We are given an array of positive integers, and we define a number as special if the power of 6 that divides it is strictly greater than the power of 7 that divides it.

codeforcescompetitive-programmingdivide-and-conquermathnumber-theorystringstrees
CF 2200G - Operation Permutation

We are given a starting integer $x$ and a list of $n$ operations, each of which modifies $x$ by either addition, subtraction, multiplication, or division by a positive integer. The twist is that the operations are applied in a random order: all $n!

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 2200F - Mooclear Reactor 2

We are given a collection of particles, each with an energy value and a reactivity limit. A particle's reactivity determines the maximum number of other particles that can coexist with it in the reactor.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementationsortings
CF 2200D - Portal

We are given a permutation arranged on a line and two special cutting points, called portals. These portals divide the array into segments and define where elements can be extracted from and reinserted.

codeforcescompetitive-programminggreedysortings
CF 2200E - Divisive Battle

We are given an array of positive integers and two players who alternate turns, starting with Alice. The game evolves by either ending immediately if the current array is already non-decreasing, or by performing a single allowed operation on a chosen element.

codeforcescompetitive-programminggamesgreedymathnumber-theory
CF 2200A - Eating Game

We are given a circular table with n players, each having a certain number of dishes they must eat. Players take turns sequentially around the table, and during a player’s turn, if they have any dishes left, they must eat exactly one.

codeforcescompetitive-programminggreedy
CF 2200C - Specialty String

We are given a string consisting of lowercase letters, and the game involves repeatedly replacing pairs of equal letters with asterisks, provided that all characters between them have already become asterisks.

codeforcescompetitive-programmingbrute-forcegreedystrings
CF 2200B - Deletion Sort

We are given several independent test cases. In each one, we start with a short array of positive integers and repeatedly remove elements until the remaining array is sorted in non-decreasing order.

codeforcescompetitive-programmingbitmasksbrute-forcegreedysortings
CF 2201G - Codeforces Heuristic Contest 1001

We are given a grid of size $n times n$ where each cell can be thought of as a vertex labeled by its row and column $(r,c)$. Two vertices are connected if the squared Euclidean distance between them is exactly 13.

codeforcescompetitive-programmingconstructive-algorithms
CF 2201F2 - Monotone Monochrome Matrices (Hard Version)

We start with an $n times n$ grid that is completely empty, and we gradually paint some cells black. After each paint operation, we must decide whether the current black-white pattern avoids a very specific forbidden configuration involving two rows and two columns.

codeforcescompetitive-programmingconstructive-algorithmsdata-structureshashingmath
CF 2201F1 - Monotone Monochrome Matrices (Medium Version)

We are maintaining an $n times n$ grid that starts completely empty in the sense that every cell is white. Over time, we flip certain cells to black, one at a time, and after each flip we must decide whether the current black-white pattern satisfies a structural restriction…

codeforcescompetitive-programmingdata-structureshashing
CF 2201E - ABBA Counting

We are given a string T of even length n, consisting of the characters 'a', 'b', and '?'. The question asks us to count all possible strings S that match T wherever T specifies a character (i.e., S[i] = T[i] when T[i] is not '?

codeforcescompetitive-programmingfftmathnumber-theorystrings
CF 2201D - Binary Not Search and Queries

We are given a sequence of integers and a set of queries that modify elements of the sequence. After each modification, we are asked to compute two values derived from the sequence: the maximum length of two subarrays that are permutations of each other, and how many pairs of…

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 2201A1 - Lost Civilization (Easy Version)

We are given a sequence of integers that has been generated by a very simple algorithm: start with some initial sequence of length m, and repeatedly choose an element and insert its value plus one immediately after it until the sequence reaches length m + k.

codeforcescompetitive-programmingdata-structures