brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1656E - Equal Tree Sums

We are given a tree, and we must assign a nonzero integer to every vertex. The constraint is not about the whole tree sum, but about what happens when a vertex is removed. If we delete any vertex $v$, the tree splits into several connected components.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similarmathtrees
CF 1654D - Potion Brewing Class

We are given a set of ingredients, each of which must appear in some positive integer quantity in a final mixture. The professor does not provide absolute amounts, but instead gives exactly $n-1$ constraints.

codeforcescompetitive-programmingdfs-and-similarmathnumber-theorytrees
CF 1654H - Three Minimums

We are asked to count permutations of the numbers from 1 to n that satisfy two independent kinds of restrictions. The first restriction is positional and local. We are given a short comparison string s of length m.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdivide-and-conquerdpfftmath
CF 1654G - Snowy Mountain

We are given a tree where some vertices are marked as “base lodges”. Every vertex inherits a height equal to its distance from the nearest lodge.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsgreedyshortest-pathstrees
CF 1654B - Prefix Removals

We are repeatedly trimming a string from the front based on a self-referential property of its prefixes. At any moment, we look at the current string and examine all its prefixes starting from the empty one.

codeforcescompetitive-programmingstrings
CF 1654F - Minimal String Xoration

We are given a string whose length is a power of two, indexed from 0 to $2^n - 1$. The key operation allowed is a global reindexing of the string using bitwise XOR with a fixed mask $j$.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquergreedyhashingsortingsstrings
CF 1646F - Playing Around the Table

We are given a circular arrangement of $n$ players, each holding exactly $n$ cards. Every card carries a label from $1$ to $n$, and each label appears exactly $n$ times across the whole system.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1646E - Power Board

We are looking at a grid where each position is completely deterministic: the cell in row $i$ and column $j$ contains the value $i^j$.

codeforcescompetitive-programmingbrute-forcedpmathnumber-theory
CF 1646D - Weight the Tree

We are given a tree, and we must assign a positive integer weight to every vertex. A vertex is called good if its weight equals the sum of the weights of all vertices adjacent to it. The goal is not just to satisfy this condition arbitrarily.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpimplementationtrees
CF 1593B - Make it Divisible by 25

We are given a number written in decimal form, and we are allowed to delete digits one by one from anywhere in the number. After each deletion, the remaining digits close up, and any leading zeros disappear automatically.

codeforcescompetitive-programmingdfs-and-similardpgreedymath
CF 1593G - Changing Brackets

We are given a string made of four types of brackets: round (, ) and square [ , ]. Each query gives a substring, and for that substring we want to know the cheapest way to turn it into a valid bracket sequence. We are allowed to perform two kinds of transformations.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdpgreedy
CF 1593C - Save More Mice

We are given a line segment with three types of entities: a cat starting at position 0, a hole at position n, and several mice positioned strictly between them. Time advances in discrete seconds.

codeforcescompetitive-programmingbinary-searchgreedy
CF 1583H - Omkar and Tours

We are given a tree of cities. Each city has a fixed value called enjoyment. Each road connects two cities and has two properties: a capacity and a toll. A group query gives a starting city and a number of vehicles.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortingstrees
CF 1583E - Moment of Bloom

We are given a connected undirected graph where every edge initially has weight 0. We then receive a sequence of queries, each query specifying two vertices. For each query, we must choose a simple path between its endpoints and add 1 to every edge along that path.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraph-matchingsgraphsgreedytrees
CF 1583G - Omkar and Time Travel

Each task has two special moments: the moment Okabe learns about it, and the earlier time at which it should actually be completed. When he learns about a task, he either confirms it is already done correctly, or he is forced to jump back in time to fix it immediately.

codeforcescompetitive-programmingdata-structuresmath
CF 1583F - Defender of Childhood Dreams

We are given a complete directed acyclic graph on the vertices from 1 to n, where every pair (i, j) with i < j has a directed edge from i to j.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquer
CF 1583B - Omkar and Heavenly Tree

We are asked to construct a tree on $n$ labeled nodes, where a tree means a connected graph with exactly $n-1$ edges and a unique simple path between every pair of nodes. Alongside this, we are given $m$ constraints.

codeforcescompetitive-programmingconstructive-algorithmstrees
CF 1583D - Omkar and the Meaning of Life

We are trying to recover an unknown permutation of the numbers from 1 to n. We never see this permutation directly. Instead, we can probe it using a query mechanism that mixes our chosen array with the hidden permutation in a very specific way.

codeforcescompetitive-programmingconstructive-algorithmsgreedyinteractive
CF 1583A - Windblume Ode

We are given several independent test cases. In each test case there is an array of distinct positive integers, and the task is to choose as many elements as possible such that the sum of the chosen elements is not prime.

codeforcescompetitive-programmingmathnumber-theory
CF 1582G - Kuzya and Homework

We are given a sequence of numbers and a sequence of operations placed between them. We start each segment with value 1, then apply the operations from left to right. Each position either multiplies the current value by the given number or divides it by that number.

codeforcescompetitive-programmingdata-structuresnumber-theory
CF 1582D - Vupsen, Pupsen and 0

We are given several test cases. In each one, we start with an array of nonzero integers $a$. Our task is to construct another array $b$ of the same length such that two conditions hold simultaneously. First, no element of $b$ is allowed to be zero.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1582E - Pchelyonok and Segments

We are given an array of positive integers and asked to construct a sequence of non-overlapping subarrays. These subarrays must be chosen in order from left to right, and their lengths are fixed to form a decreasing sequence starting from some value $k$ down to $1$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedymath
CF 1582C - Grandma Capa Knits a Scarf

We are given a string made of lowercase letters. We are allowed to pick exactly one letter of the alphabet, and then delete any occurrences of that chosen letter from the string, possibly none or all of them.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedystringstwo-pointers
CF 1582A - Luntik and Concerts

We are given a collection of songs split into three types: some last 1 minute, some last 2 minutes, and some last 3 minutes. For each test case, we must assign every song to one of two concerts.

codeforcescompetitive-programmingmath
CF 1578M - The Mind

Each test gives us a hand of five distinct numbers between 1 and 100. Two players independently receive such hands, and each player only sees their own five numbers.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilities
CF 1578L - Labyrinth

The labyrinth can be seen as a connected weighted graph where rooms are nodes and passages are undirected edges with capacities. Each room also has a one-time “growth value” that increases Lucy’s width if she chooses to eat that room’s candy.

codeforcescompetitive-programmingbinary-searchdsugreedy
CF 1578K - Kingdom of Islands

We are given a set of jarls, each belonging to exactly one island. The default rule of conflict is simple: jarls from different islands are in conflict, while jarls from the same island are peaceful.

codeforcescompetitive-programmingbrute-forcegraphsimplementation
CF 1578J - Just Kingdom

We are given a rooted hierarchy with a single root, the king, and up to $n$ lords forming a tree where each lord has exactly one parent. Each lord $i$ has a required amount of money $mi$.

codeforcescompetitive-programmingbrute-forcedata-structuresdfs-and-similar
CF 1578F - Framing Pictures

We are given a convex polygon in the plane, and this polygon represents the silhouette of an object. We imagine rotating the viewing direction uniformly at random, and for each orientation we project the polygon onto axes aligned with that view.

codeforcescompetitive-programminggeometry
CF 1578G - Game of Chance

We are given a line of participants, each assigned a positive “luckiness” value. These participants enter a knockout tournament with a very rigid pairing structure.

codeforcescompetitive-programmingmathprobabilities
CF 1578B - Building Forest Trails

We are given a circular arrangement of villages, labeled from 1 to n in clockwise order. Initially there are no connections between any pair of villages.

codeforcescompetitive-programmingdata-structuresdsu
CF 1578A - Anti-Tetris

We are given a final board configuration of a grid-based stacking process where multiple small polyomino-like pieces were dropped one after another. Each piece is connected in four directions, has at most seven cells, and is identified by a letter.

codeforcescompetitive-programmingconstructive-algorithmsgraphsshortest-paths
CF 1561A - Simply Strange Sort

We are given a permutation, meaning an array containing every integer from 1 to n exactly once. The process repeatedly applies a deterministic “strange bubble pass” operation, but with a twist: odd-numbered rounds compare adjacent pairs starting from index 1, 3, 5, and…

codeforcescompetitive-programmingbrute-forceimplementationsortings
CF 1560F1 - Nearest Beautiful Number (easy version)

We are given a starting number and a restriction on how many distinct digits we are allowed to use. For each query, we must find the smallest integer that is not smaller than the given number and whose decimal representation uses at most k different digits.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forceconstructive-algorithmsdfs-and-similargreedy
CF 1560D - Make a Power of Two

We are given a number written as a string of digits. In one operation, we are allowed to either remove any single digit from anywhere in the current string, or append a single digit to the right end of the string. These operations can be repeated in any order.

codeforcescompetitive-programminggreedymathstrings
CF 1557C - Moamen and XOR

We are counting how many arrays of length n can be formed when each element is an integer in the range [0, 2^k - 1], with the additional constraint that a certain bitwise inequality holds.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathmatrices
CF 1556H - DIY Tree

We are given a complete weighted undirected graph on $n$ vertices, so every pair of vertices is connected and every edge has a known cost.

codeforcescompetitive-programminggraphsgreedymathprobabilities
CF 1556G - Gates to Another World

We are working on a graph whose vertices are all integers from $0$ to $2^n - 1$. Each vertex represents an $n$-bit binary string, and there is an undirected edge between two vertices if their binary representations differ in exactly one bit.

codeforcescompetitive-programmingbitmasksdata-structuresdsutwo-pointers
CF 1556D - Take a Guess

We are given a hidden array of integers, and we cannot access its elements directly. The only way to learn anything about the array is by asking queries on pairs of indices. Each query returns either the bitwise AND or bitwise OR of two elements.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractivemath
CF 1556E - Equilibrium

We are given two arrays of the same length and a set of queries, each query picking a contiguous segment. Inside a segment, we are allowed to perform a special operation multiple times. Each operation selects an even number of distinct positions inside the segment.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1556F - Sports Betting

We are given a complete tournament where every pair of teams plays exactly one match. The result of each match is random, but biased: team $i$ beats team $j$ with probability proportional to its strength, specifically $frac{ai}{ai + aj}$. Each match outcome is independent.

codeforcescompetitive-programmingbitmaskscombinatoricsdpgraphsmathprobabilities
CF 1556C - Compressed Bracket Sequence

We are given a bracket string, but it is not written explicitly character by character. Instead, it is compressed into blocks.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1556A - A Variety of Operations

We start with two integers, both initialized to zero. We are allowed to repeatedly apply operations that modify them using a freely chosen positive step size each time.

codeforcescompetitive-programmingmath
CF 1556B - Take Your Places!

We are given an array of integers, and we are allowed to swap adjacent elements. The goal is to rearrange the array so that no two neighboring elements share the same parity, meaning we want an alternating pattern of even and odd numbers.

codeforcescompetitive-programmingimplementation
CF 1555B - Two Tables

We are given a rectangular room and inside it a fixed axis-aligned rectangular table. The table currently occupies a block inside the room, but we are allowed to slide this table anywhere inside the room as long as it stays fully inside the boundary.

codeforcescompetitive-programmingbrute-force
CF 1555E - Boring Segments

We are given a set of weighted intervals on a number line from 1 to m. Each interval allows free movement between any two integer points inside it, which effectively means that once we pick a set of intervals, all points covered by overlapping intervals become connected…

codeforcescompetitive-programmingdata-structuressortingstreestwo-pointers
CF 1555A - PizzaForces

We are asked to build an order of pizzas where each pizza contributes both a fixed number of slices and a fixed baking time.

codeforcescompetitive-programmingbrute-forcemath
CF 1555D - Say No to Palindromes

We are given a string made only of three possible letters. For any substring, we are allowed to change characters, and each change replaces a character with any of the three letters.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdpstrings
CF 1554B - Cobb

We are given an array of values indexed from one, and we want to choose two different positions in this array. For any chosen pair of indices, we compute a score made of two competing parts: a positive term that grows with the product of the indices, and a penalty term that…

codeforcescompetitive-programmingbitmasksbrute-forcegreedymath
CF 1553I - Stairs

We are given an array a of length n. It is not a permutation itself but a derived “stability profile” of an unknown permutation of 1..n. For each position i in that hidden permutation, we look at all subarrays that contain i.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpfftmath
CF 1553A - Digits Sum

We are given several independent queries. Each query provides a positive integer $n$, and we must count how many integers $x$ in the range from 1 to $n$ have a special property. For a number $x$, we compare the sum of its digits before and after adding one.

codeforcescompetitive-programmingmathnumber-theory
CF 1552F - Telepanting

We are simulating a point moving on a number line. The point starts at position 0 and moves strictly to the right at unit speed, so without any interruptions it would simply take $t$ seconds to reach position $t$.

codeforcescompetitive-programmingbinary-searchdata-structuresdpsortings
CF 1552A - Subsequence Permutation

We are given a string made of lowercase letters. In one move, we are allowed to pick exactly one subset of positions, take the characters at those positions, and rearrange only those chosen characters arbitrarily while keeping all other characters fixed in their original places.

codeforcescompetitive-programmingsortingsstrings
CF 1551F - Equidistant Vertices

The task is about selecting a subset of vertices in a tree such that every pair of chosen vertices is equally far apart.

codeforcescompetitive-programmingbrute-forcecombinatoricsdfs-and-similardptrees
CF 1551D2 - Domino (hard version)

We are given a rectangular grid with $n$ rows and $m$ columns, and we must tile it completely using dominoes, each covering exactly two adjacent cells. Every cell must belong to exactly one domino, so the grid is fully partitioned into pairs of neighbors.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1551B2 - Wonderful Coloring - 2

We are given several test cases. In each case there is a sequence of integers and a number of colors. We want to “paint” some occurrences of these integers using up to $k$ colors, with the option to leave elements unpainted. The constraints inside the coloring are subtle.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedy
CF 1551C - Interesting Story

We are given several independent test cases. In each test case, we receive a list of words, and we want to select as many of these words as possible so that the selected subset satisfies a specific imbalance condition.

codeforcescompetitive-programminggreedysortingsstrings
CF 1550C - Manhattan Subarrays

We are given an array where each element represents a point on a vertical line at its index. More precisely, the i-th element forms a point $(ai, i)$ in a 2D plane. The distance between two points is measured using Manhattan distance.

codeforcescompetitive-programmingbrute-forcegeometrygreedyimplementation
CF 1550E - Stringforces

We are given a string made of lowercase letters from a small alphabet of size $k$, plus wildcard characters that can be replaced freely.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcedpstringstwo-pointers
CF 1550F - Jumping Around

We are given a sorted set of points on a number line, which we can think of as rocks placed at distinct integer coordinates. A frog starts on one designated rock and can repeatedly jump to other rocks.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdpdsugraphsshortest-paths
CF 1550D - Excellent Arrays

We are given an array of length $n$, and each position $i$ must store an integer $ai$ within a fixed interval $[l, r]$. Two constraints define what makes a valid configuration interesting.

codeforcescompetitive-programmingbinary-searchcombinatoricsconstructive-algorithmsimplementationmathsortingstwo-pointers
CF 1550A - Find The Array

We are asked to construct an array of positive integers whose elements sum to a fixed value, while keeping the array as small as possible in length.

codeforcescompetitive-programminggreedymath
CF 1549B - Gregor and the Pawn Game

We are given a square board of size $n times n$, but only the first and last rows matter. The bottom row contains Gregor’s pawns, and the top row contains enemy pawns. Every column is either empty or occupied independently in those two rows.

codeforcescompetitive-programmingdfs-and-similardpflowsgraph-matchingsgraphsgreedyimplementation
CF 1549A - Gregor and Cryptography

We are given a prime number $P$, and for each test case we must output two integers $a$ and $b$ such that both lie between 2 and $P$, with $a < b$, and the remainders when dividing $P$ by $a$ and by $b$ are equal.

codeforcescompetitive-programmingmathnumber-theory
CF 1548E - Gregor and the Two Painters

The ceiling is split into a grid where each row contributes a fixed amount of paint and each column contributes another fixed amount. This makes every cell’s paint level completely determined by two arrays: one attached to rows and one attached to columns.

codeforcescompetitive-programmingdata-structuresdivide-and-conquergraphsgreedymath
CF 1548D2 - Gregor and the Odd Cows (Hard)

We are given a set of points on the plane that act as fixed vertices. From these points, we choose any three distinct points to form a triangle. Inside this triangle lies an infinite integer grid of “cows”, one at every lattice point.

codeforcescompetitive-programmingbrute-forcegeometrymathnumber-theory
CF 1548D1 - Gregor and the Odd Cows (Easy)

We are given a set of points on a plane that serve as possible vertices of a triangle. Every point has even integer coordinates, and no three points are collinear. From these points we choose any triple and form a triangle.

codeforcescompetitive-programmingbitmasksgeometrymathnumber-theory
CF 1548C - The Three Little Pigs

We are looking at a process that lasts for $n$ minutes. Each minute, exactly three new items are added, so after minute $t$, there are $3t$ items available.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1548A - Web of Lies

We are working with a graph whose vertices are fixed nobles numbered from 1 to n, where the label also represents their strength. Edges represent mutual friendships, and these edges change over time through insertions and deletions.

codeforcescompetitive-programmingbrute-forcegraphsgreedy
CF 1547G - How Many Paths?

We are given a directed graph where we start from node 1 and consider all possible directed walks that end at each vertex. A walk can revisit nodes and edges arbitrarily many times.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 1547E - Air Conditioners

We are given a one-dimensional strip of length $n$. Some positions on this strip contain air conditioners, each fixed at a known coordinate and each producing its own base temperature.

codeforcescompetitive-programmingdata-structuresdpimplementationshortest-pathssortingstwo-pointers
CF 1547D - Co-growing Sequence

We are given a sequence $x1, x2, dots, xn$. Our task is to construct another sequence $y1, y2, dots, yn$ such that when we XOR them elementwise, the resulting sequence $$ai = xi oplus yi$$ has a monotone bit-structure: every bit that is set in $ai$ must also be set in $a{i+1}$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedy
CF 1547C - Pair Programming

Two programmers are contributing edits to the same file, but their work histories are interleaved in time. We are given two ordered sequences of actions, one for each person. Each action is either an insertion at the end of the file or an edit of an existing line.

codeforcescompetitive-programminggreedytwo-pointers
CF 1547B - Alphabetical Strings

We are given a string and we need to decide whether it could have been constructed by a very specific process that builds strings from left to right choices.

codeforcescompetitive-programminggreedyimplementationstrings
CF 1547A - Shortest Path with Obstacle

We are working on an infinite grid where movement is allowed in four directions: up, down, left, and right, each costing one step. We are given three special cells: a start cell, a target cell, and a forbidden cell that cannot be stepped on.

codeforcescompetitive-programmingimplementationmath
CF 1546B - AquaMoon and Stolen String

We are given a multiset of original strings and a second multiset formed after a disturbance process. The disturbance worked in two stages. First, all strings were paired except one special string that stayed unpaired.

codeforcescompetitive-programminginteractivemath
CF 1546A - AquaMoon and Two Arrays

Two players give us two arrays of equal length. One array can be modified by repeatedly moving a single unit from one position to another position. Each move removes one from index i and adds one to index j, and the array must remain non-negative after every move.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1545E1 - AquaMoon and Time Stop (easy version)

A single person moves deterministically along a number line: starting from position $x$ at time $0$, his position at time $t$ is exactly $x+t$.

codeforcescompetitive-programmingdata-structuresdp
CF 1545E2 - AquaMoon and Time Stop (hard version)

We are given a person who moves deterministically along a number line: starting at position $x$ at time $0$, and then increasing position by exactly one unit per second. So at time $t$, the person is at $x+t$.

codeforcescompetitive-programmingdata-structuresdp
CF 1545C - AquaMoon and Permutations

We are given $2n$ permutations of size $n$. Each row is a rearrangement of numbers $1$ to $n$. We are promised that there exists a hidden structure behind these rows: they originally came from two intertwined Latin squares of size $n$, but then the rows were shuffled.

codeforcescompetitive-programming2-satbrute-forcecombinatoricsconstructive-algorithmsgraph-matchingsgraphs
CF 1545B - AquaMoon and Chess

We are given a binary string of length $n$, where each position either contains a pawn or is empty. The board is a line, and pawns can move only in a very constrained way: a pawn can “jump” two cells left or right, but only if the intermediate cell is occupied and the…

codeforcescompetitive-programmingcombinatoricsmath
CF 1543E - The Final Pursuit

The input describes a graph that is guaranteed to be a permuted hypercube. This means the graph has exactly $2^n$ vertices, every vertex has degree exactly $n$, and the structure is isomorphic to the standard $n$-dimensional hypercube, but the vertex labels have been…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergraphsgreedymath
CF 1543C - Need for Pink Slips

We are repeatedly running a stochastic process that evolves a small probability distribution over three outcomes. At any moment there are up to three “active” slips, one of which is a terminal success state (the pink slip) and the other two are transient states.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similarimplementationmathprobabilities
CF 1543B - Customising the Track

We are given a list of non-negative integers where each value represents how many cars sit on a segment of a road. The “cost” of the whole configuration is defined by comparing every pair of segments and summing the absolute difference of their car counts.

codeforcescompetitive-programmingcombinatoricsgreedymath
CF 1542C - Strange Function

We are given many queries. Each query provides a very large integer $n$, and we consider every integer $i$ from 1 to $n$. For each $i$, we define a function $f(i)$ as the smallest positive integer that fails to divide $i$.

codeforcescompetitive-programmingmathnumber-theory
CF 1538F - Interesting Function

We are effectively watching a number grow from l to r by repeatedly adding one, and we want to measure how “violent” each increment is in terms of decimal digit changes.

codeforcescompetitive-programmingbinary-searchdpmathnumber-theory
CF 1538A - Stone Game

We are given a row of stones, each stone having a distinct strength value. In one move, we are allowed to remove only one of the two boundary stones, either the leftmost or the rightmost remaining stone.

codeforcescompetitive-programmingbrute-forcedpgreedy
CF 1536E - Omkar and Forest

We are given a grid where some cells are forced to be zero and the rest are flexible cells that may take any non-negative integer value.

codeforcescompetitive-programmingcombinatoricsgraphsmathshortest-paths
CF 1536D - Omkar and Medians

We are given a sequence b which is claimed to come from a hidden process involving another array a. The process builds a step by step in odd lengths: at step i, we look at the first 2i-1 elements of a, compute their median, and store it as b[i].

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1536C - Diluc and Kaeya

We are given a binary string made only of the characters D and K. For every prefix of this string, we want to determine how finely we can split that prefix into contiguous pieces such that every piece has the same internal balance between D and K.

codeforcescompetitive-programmingdata-structuresdphashingnumber-theory
CF 1536B - Prinzessin der Verurteilung

We are given a short lowercase string and asked to find a very specific “missing pattern” inside it. The task is to identify the shortest possible string over lowercase letters that does not appear anywhere as a contiguous substring of the given input.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsstrings
CF 1536A - Omkar and Bad Story

We are given a small set of distinct integers and are allowed to add new distinct integers to it. The goal is to build a final set such that it satisfies a very strong closure property: whenever we pick any two numbers from the set, the absolute difference between them must…

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1533I - Excursions

We can view the situation as a two-layer directed routing process between two bipartite sets of nodes. One set corresponds to sights in Saratov, the other to sights in Engels.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similarflowsgraph-matchingsgraphs
CF 1533G - Biome Map

We are given a small grid of biome “types”, where each type is identified by a pair of parameters coming from a fixed $n times m$ table. Some of these pairs exist and are assigned a unique integer identifier, while others are unavailable.

codeforcescompetitive-programming*specialconstructive-algorithmsdfs-and-similargraphs
CF 1533H - Submatrices

We are working with a grid of uppercase letters, but the alphabet is extremely small: only the first five letters appear.

codeforcescompetitive-programming*specialbitmasksdata-structuresdp
CF 1533D - String Searching

We are given a fixed collection of strings, all of the same length, and we are asked to answer many queries about a slightly longer string. Each stored string has length $m$. Each query string has length $m+1$.

codeforcescompetitive-programming*specialhashing
CF 1533C - Sweets

We are given a circular arrangement of sweets labeled from 1 to n. Each sweet is either “liked” or “not liked”. Anya performs a deterministic process that removes sweets one by one from the circle. The process has two phases in every test case.

codeforcescompetitive-programming*specialdata-structuresimplementation
CF 1533A - Travel to Bertown

Vika arrives in Bertown on a fixed day $k$. She has several friends, and each friend offers a single continuous interval of days during which she can stay at their home.

codeforcescompetitive-programming*specialimplementationmath
CF 1533B - Nearest Point Function

We are given several test cases, each consisting of a sorted array of distinct integers. Think of these numbers as fixed points on a number line. A query point $y$ is chosen, and a function returns the closest point in the array to $y$ based on absolute distance.

codeforcescompetitive-programming*specialimplementation
CF 1532F - Prefixes and Suffixes

We are given a multiset of strings that all come from a single unknown string of length $n$. For every length $k$ from $1$ to $n-1$, we are given exactly two strings of that length, and each of those two strings is either a prefix or a suffix of the hidden string.

codeforcescompetitive-programming*specialstrings