brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1913E - Matrix Problem

We start with a binary matrix. Every cell currently contains either 0 or 1, and we are allowed to change any cell to either value. Changing a cell counts as one operation. The final matrix must satisfy two independent requirements.

codeforcescompetitive-programmingflowsgraphs
CF 1913D - Array Collapse

We are given a permutation-like array where all values are distinct. The only operation allowed takes a contiguous segment and compresses it down to just its minimum element, deleting everything else in that segment.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdptrees
CF 1913F - Palindromic Problem

We are given a string consisting of lowercase letters, and we are allowed to change at most one character to any other lowercase letter. The goal is to produce a string that maximizes the number of palindromic substrings.

codeforcescompetitive-programmingbinary-searchdata-structureshashingstring-suffix-structuresstrings
Kvant Math Problem 1502

Let the regular $2n$-gon have vertices labeled $A=A_0, A_1, \dots, A_{2n-1}$ in cyclic order.

kvantmathematicsolympiad
CF 1913A - Rating Increase

We are given a string of digits that represents two concatenated integers, the original rating a and the increased rating b, but without a clear separation between them.

codeforcescompetitive-programmingimplementation
CF 1913B - Swap and Delete

We start with a binary string s. We may delete characters, paying one coin per deletion, and we may swap any pair of remaining characters for free. After all operations, we obtain a string t.

codeforcescompetitive-programmingstrings
CF 1913C - Game with Multiset

We are maintaining a dynamic collection of powers of two. Each time we receive an ADD operation, we insert a value of the form $2^x$ into the multiset.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcegreedy
CF 1914G2 - Light Bulbs (Hard Version)

We are given a row of $2n$ light bulbs, with each color from $1$ to $n$ appearing exactly twice. All bulbs start turned off. We are allowed to initially turn on any subset $S$ of bulbs.

codeforcescompetitive-programmingcombinatoricsdata-structuresdfs-and-similardpgraphshashing
CF 1914F - Programming Competition

We are given a company hierarchy with n employees, where the first employee is the head, and every other employee has exactly one direct superior. This naturally forms a rooted tree with the head as the root.

codeforcescompetitive-programmingdfs-and-similardpgraph-matchingsgreedytrees
CF 1914E1 - Game with Marbles (Easy Version)

Each color is an independent pile of marbles owned by both players. A move chooses a color that still exists on both sides. Suppose color i is chosen by Alice. Alice throws away exactly one of her marbles of that color, while Bob loses all bi marbles of that color.

codeforcescompetitive-programmingbrute-forcegamesgreedysortings
CF 1914G1 - Light Bulbs (Easy Version)

We are given a row of 2n light bulbs, with exactly two bulbs of each color from 1 to n. All bulbs start turned off. We can pick an initial set S of bulbs to turn on.

codeforcescompetitive-programmingbrute-forcecombinatoricsdfs-and-similardpdsugraphsmathtrees
CF 1914E2 - Game with Marbles (Hard Version)

Alice and Bob each have collections of marbles in $n$ colors. Alice's collection is represented as an array $a$, and Bob's as an array $b$, where $ai$ and $bi$ denote the number of marbles of color $i$ each player has.

codeforcescompetitive-programminggamesgreedysortings
CF 1914D - Three Activities

Each test case gives three arrays of equal length, where each index represents a day in a holiday period. On any given day, Monocarp has three independent “options”: how many friends would join if he goes skiing that day, how many would join for a movie that day, and how…

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationsortings
CF 1914B - Preparing for the Contest

We have problems with difficulties 1 through n. We must arrange these numbers into a permutation that represents the order in which Monocarp solves them. Whenever a problem is harder than the immediately previous problem in the chosen order, Monocarp becomes excited.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1914A - Problemsolving Log

Monocarp's contest log is a string of length $n$ where the $i$-th character represents the problem he was working on during minute $i$. Each problem from 'A' to 'Z' has an associated required time to solve: 'A' takes 1 minute, 'B' 2 minutes, up to 'Z' which takes 26 minutes.

codeforcescompetitive-programmingimplementationstrings
CF 1914C - Quests

We are given a sequence of quests arranged in a strict order from 1 to n. The important rule is that quests behave like a chain of unlocks. Quest 1 is always usable. Quest i only becomes usable once every quest before it has been completed at least once.

codeforcescompetitive-programminggreedymath
CF 1915G - Bicycles

We are given a map of cities connected by roads, where each road has a fixed distance. Slavic starts at city 1 and wants to reach city n. The twist is that he does not own a bike initially, but every city has exactly one bike with a certain slowness factor.

codeforcescompetitive-programminggraphsgreedyimplementationshortest-pathssortings
CF 1915E - Romantic Glasses

We are given a line of glasses, each containing a certain amount of juice. Iulia drinks from the odd-numbered glasses and her date drinks from the even-numbered glasses.

codeforcescompetitive-programmingdata-structuresgreedymath
CF 1915F - Greetings

We are given a set of people on a one-dimensional number line. Each person has a starting point and a destination, and all starting and ending points are distinct. Everyone begins moving simultaneously at a constant speed of one unit per second toward their destination.

codeforcescompetitive-programmingdata-structuresdivide-and-conquersortings
CF 1915D - Unnatural Language Processing

We are given a sequence of letters consisting only of a, b, c, d, and e. The letters are divided into vowels (a and e) and consonants (b, c, d).

codeforcescompetitive-programminggreedyimplementationstrings
CF 1915C - Can I Square?

We are given several buckets, and each bucket contains some number of unit squares. All squares are identical and have side length 1. The question is simple: if we take every square from every bucket, can they be arranged to form one larger square with no squares left over?

codeforcescompetitive-programmingbinary-searchimplementation
CF 1915B - Not Quite Latin Square

We are given a fixed 3 by 3 grid containing the characters A, B, and C, with the structure of a Latin square except for one missing cell. A valid Latin square here means that each row contains exactly one of each letter A, B, and C, and the same holds for each column.

codeforcescompetitive-programmingbitmasksbrute-forceimplementation
CF 1915A - Odd One Out

We are given a stream of very small independent tasks. Each task consists of exactly three digits, and we are promised a specific structure: among the three values, two are identical and one is different.

codeforcescompetitive-programmingbitmasksimplementation
Kvant Math Problem 1500

Represent the group by a simple graph $G$ with $50$ vertices.

kvantmathematicsolympiad
CF 1916H2 - Matrix Rank (Hard Version)

We are asked to count the number of $n times n$ matrices over a finite field of size $p$ (integers modulo a prime $p$) that have an exact rank $r$, for every $r$ from 0 to $k$.

codeforcescompetitive-programmingcombinatoricsdpmathmatricesstring-suffix-structures
CF 1916H1 - Matrix Rank (Easy Version)

We are working over an $n times n$ matrix whose entries lie in a finite field of size $p$, meaning every entry is an integer modulo $p$ and arithmetic behaves like linear algebra over a field.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmathmatrices
CF 1916G - Optimizations From Chelsu

We are given a tree whose edges carry positive integer weights. For any two vertices $u$ and $v$, let $len(u,v)$ be the number of edges on their path, and let $gcd(u,v)$ be the gcd of all edge weights on that path.

codeforcescompetitive-programmingdivide-and-conquerdpnumber-theorytrees
CF 1916F - Group Division

We are given a social graph of students at a school, with some known friendly connections. The total number of students is $n1 + n2$, where $n1$ and $n2$ are the desired sizes of two distinct groups: computer scientists and mathematicians.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphsgreedy
CF 1916E - Happy Life in University

We are given a rooted tree. Each node has a label representing an “activity type”. For any two nodes $u$ and $v$, we look at their lowest common ancestor $w$.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
CF 1916A - 2023

We start with an unknown array a whose product of all elements is exactly 2023. Some k elements were removed, leaving the array b of length n. The task is to determine whether such an original array could exist. If it can, we must output any valid set of k removed numbers.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmathnumber-theory
CF 1916C - Training Before the Olympiad

We are given an array and asked to repeatedly reduce it until only one number remains. A move picks two elements, removes them, and inserts a new value derived from their sum: take the average of the pair, round it down, and then multiply by two.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedyimplementationmath
CF 1916D - Mathematical Problem

We are asked to construct a set of numbers with a very specific structure. Each test case provides an odd integer $n$, which has a dual meaning: it is both the number of numbers we need to produce and the number of digits each of those numbers must have.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgeometrymath
CF 1916B - Two Divisors

We are given two integers, $a$ and $b$, which are the two largest proper divisors of some unknown integer $x$. Here, $1 le a < b < x$, and our task is to find any integer $x$ that fits this description.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1917F - Construct Tree

We are given the lengths of all edges that must appear in a tree. The tree has exactly $n$ edges and $n+1$ vertices, so every length from the array is used exactly once as an edge weight.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdptrees
CF 1917B - Erase First or Second Letter

We are given a string and two operations: removing the first character or removing the second character of the current string. The task is to count how many distinct non-empty strings can be generated by applying these operations any number of times in any order.

codeforcescompetitive-programmingbrute-forcecombinatoricsdata-structuresdpstrings
CF 1918E - ace5 and Task Order

We are given a hidden permutation of integers from 1 to $n$. The permutation is unknown, and our goal is to determine it.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquerimplementationinteractiveprobabilitiessortings
CF 1918F - Caterpillar on a Tree

The previous attempts failed for two reasons. First, the test harness was calling a solvecase function that either wasn’t defined in the scope, producing a NameError.

codeforcescompetitive-programmingdfs-and-similargraphsgreedyimplementationsortingstrees
CF 1918G - Permutation of Given

We are asked to construct an array of length $n$ containing non-zero integers such that if we replace each element by the sum of its neighbors, the resulting array is a permutation of the original array. For the endpoints, the "neighbor sum" is just the single adjacent element.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1918D - Blocking Elements

We are given an array of positive integers. Our goal is to "block" some elements in order to minimize a certain cost.

codeforcescompetitive-programmingbinary-searchdata-structuresdpimplementationtwo-pointers
CF 1918C - XOR-distance

The problem asks us to minimize the absolute difference between two numbers after each has been XOR-ed with a single number $x$ that we are allowed to choose.

codeforcescompetitive-programmingbitmasksgreedyimplementationmath
CF 1918B - Minimize Inversions

We are given two permutations a and b of the same length. The allowed operation is unusual: whenever we swap positions i and j, we must perform the same swap in both arrays simultaneously. This means we can never separate a[k] from b[k].

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedyimplementationsortings
CF 1918A - Brick Wall

We are building a full $n times m$ rectangular grid using long thin bricks, where each brick is a $1 times k$ strip with $k ge 2$. Each brick must lie entirely either horizontally or vertically, and every cell of the grid must belong to exactly one brick.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1919F1 - Wine Factory (Easy Version)

Because every valve capacity is fixed at $10^{18}$, the valves never become a bottleneck. Any water that remains in tower $i$ after the wizard acts can always move completely into tower $i+1$. This changes the nature of the process dramatically.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1919H - Tree Diameter

We are asked to reconstruct an unknown tree with $n$ vertices and $n-1$ edges by interacting with a grader that allows two types of queries. The first query lets us assign arbitrary positive weights to the edges and returns the resulting diameter of the weighted tree.

codeforcescompetitive-programminginteractivetrees
Kvant Math Problem 1488

Let the squares in the sequence be

kvantmathematicsolympiad
CF 1919E - Counting Prefixes

We are asked to reverse-engineer a hidden array of size $n$ that contains only $1$ and $-1$. Instead of being given the array itself, we are given the sorted list of prefix sums of the array. The prefix sum at position $i$ is the sum of the first $i$ elements of the array.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdpimplementationmath
CF 1919G - Tree LGM

We are asked to reconstruct a tree from a matrix of game outcomes. Each entry s[i][j] indicates whether the first player can force a win when the tree is rooted at vertex i and the coin starts at vertex j. A vertex can only move the coin to its children.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquergamestrees
CF 1919F2 - Wine Factory (Hard Version)

We are tasked with simulating a sequence of water towers, each containing an initial amount of water. In front of each tower stands a wizard who can convert a limited number of liters into wine.

codeforcescompetitive-programmingdata-structuresdpflowsgreedymatrices
CF 1919C - Grouping Increases

We are given an array and we must split it into two subsequences, call them $s$ and $t$, covering every element exactly once while preserving relative order inside each subsequence.

codeforcescompetitive-programmingdata-structuresdpgreedy
CF 1919D - 01 Tree

We are given the distances from the root to the leaves of a binary tree, listed in DFS leaf order. Every internal vertex has exactly two children. One outgoing edge has weight 0 and the other has weight 1.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugreedysortingstrees
CF 1919A - Wallet Exchange

Alice and Bob each start with a wallet containing some number of coins. On every turn, the current player may either keep the wallets as they are or swap the two wallets. After that choice, they must remove exactly one coin from the wallet they currently hold.

codeforcescompetitive-programminggamesmath
CF 1919B - Plus-Minus Split

The string consists only of '+' and '-'. We can interpret each character as a number: '+' becomes +1, and '-' becomes -1. We are allowed to split this sequence into any number of contiguous non-empty pieces.

codeforcescompetitive-programminggreedy
CF 1920E - Counting Binary Strings

We are asked to count the number of binary strings such that the total number of substrings containing exactly one 1 equals a given number n, and no such substring has length exceeding a given maximum k. A substring is simply a consecutive portion of the string.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1920F2 - Smooth Sailing (Hard Version)

We are given a rectangular grid where some cells are islands, some are open ocean, and some are underwater volcanoes. Thomas wants to sail in loops that fully encircle the island without stepping onto it.

codeforcescompetitive-programmingbinary-searchdata-structuresdsugeometrygraphstrees
CF 1920F1 - Smooth Sailing (Easy Version)

We are given a 2D grid representing an island in the ocean. Each cell can be part of the island (), open ocean (.), or an underwater volcano (v). The island cells form a single contiguous shape not touching the grid edges.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdfs-and-similardsugraphsshortest-paths
CF 1920D - Array Repetition

We start with an empty sequence and gradually build a very large array using two kinds of operations. The first operation appends a single value to the end, effectively extending the sequence by one element.

codeforcescompetitive-programmingbinary-searchbrute-forcedsuimplementationmath
CF 1920A - Satisfying Constraints

We are asked to determine how many integers satisfy a set of constraints. Each test case consists of multiple constraints on a single integer $k$. The constraints fall into three categories: $k$ must be at least $x$, $k$ must be at most $x$, and $k$ must not equal $x$.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1920B - Summation Game

We are asked to simulate a two-step game played on an array of positive integers. The first player, Alice, can remove up to $k$ elements. She wants the final sum of the array to be as large as possible.

codeforcescompetitive-programminggamesgreedymathsortings
Kvant Math Problem 1486

Consider sequences $(a_1, a_2, a_3, \dots)$ satisfying the recurrence $a_k = a_{k-1} - a_{k-2}$ for $k \ge 3$, with terms chosen from the set $1, \frac12, \frac13, \dots$.

kvantmathematicsolympiad
CF 1920C - Partitioning the Array

This is a Type B problem, a proof of existence. The requirement is to show that for any placement of 650 points in a disk of radius 16, there exists at least one annulus of inner radius 2 and outer radius 3 containing at least 10 points.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1921G - Mischievous Shooter

We are given a grid of size $n times m$, each cell either containing a target represented by or empty represented by .. Shel has a shotgun that fires in one of four diagonal directions: right-down, left-down, left-up, or right-up.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquerdpimplementation
Kvant Math Problem 1490

The statement as written can only be meaningful if the second triangle has side lengths $\sin x$, $\sin y$, $\sin z$.

kvantmathematicsolympiad
CF 1921E - Eat the Chip

We have a two-player game on a rectangular grid with height h and width w. Alice’s chip starts at (xa, ya) and can move down, down-left, or down-right. Bob’s chip starts at (xb, yb) and moves up, up-left, or up-right.

codeforcescompetitive-programmingbrute-forcegamesgreedymath
CF 1921D - Very Different Array

We have an array a of length n. Another array b contains m values, where m is at least n. We are allowed to choose exactly n elements from b, then arrange those chosen elements in any order to form a new array c.

codeforcescompetitive-programmingdata-structuresgreedysortingstwo-pointers
CF 1921F - Sum of Progression

We are given an array of integers and a set of queries. Each query specifies a starting index s, a step size d, and a count k. For a query, we must sum k elements of the array taken at indices s, s+d, s+2d, ...

codeforcescompetitive-programmingbrute-forcedata-structuresdpimplementationmath
CF 1921B - Arranging Cats

The task is to transform an initial arrangement of cats in boxes into a target arrangement using the fewest operations. Each box either contains a cat or is empty, and the initial state is given by a binary string s, while the target state is given by a binary string f.

codeforcescompetitive-programminggreedyimplementation
CF 1921A - Square

We are given the four vertices of a square on a 2D coordinate plane. The points are presented in arbitrary order, so we do not know which point is the bottom-left corner, top-right corner, and so on. The square has two special properties.

codeforcescompetitive-programminggreedymath
CF 1921C - Sending Messages

Stepan needs to send a series of messages at strictly increasing moments in time. His phone starts with a finite charge, loses a constant amount per unit of time while it is on, and consumes a fixed cost if he turns it off and then back on.

codeforcescompetitive-programminggreedymath
CF 1922F - Replace on Segment

We are given an array of integers, each between 1 and some maximum value $x$. We want to make every element equal using a special operation: select a contiguous subsegment of the array and a value $k$ not currently present in that subsegment, then replace every element in that…

codeforcescompetitive-programmingdpgraph-matchings
CF 1922A - Tricky Template

We are given three strings of equal length, and we need to construct a template string such that the first two strings match the template while the third one does not. Each position in the template can be either lowercase or uppercase.

codeforcescompetitive-programmingconstructive-algorithmsimplementationstrings
CF 1922E - Increasing Subsequences

We are asked to construct an array of integers with a very specific property: the total number of its increasing subsequences should equal a given integer $X$.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdivide-and-conquergreedymath
CF 1922D - Berserk Monsters

We have a row of monsters, each with an attack value ai and a defense value di. Monocarp casts a berserk spell so that monsters attack their immediate neighbors each round.

codeforcescompetitive-programmingbrute-forcedata-structuresdsuimplementationmath
CF 1922B - Forming Triangles

We are given a set of sticks, each with a length that is a power of two. The input does not give the actual lengths directly but rather exponents $ai$ such that the stick's length is $2^{ai}$.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmathsortings
CF 1922C - Closest Cities

We are given several cities placed along a one-dimensional number line. Each city has a coordinate, and the coordinates are strictly increasing. For each city, there exists a unique "closest" city, meaning that no two cities are equally close to it.

codeforcescompetitive-programminggreedyimplementationmath
CF 1923E - Count Paths

We are given a tree with n nodes, each colored with some integer between 1 and n. The task is to count the number of simple paths of length at least two such that the first and last nodes have the same color, and no intermediate node shares this color.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugraphstrees
CF 1923D - Slimes

We are given a row of slimes, each with a positive size. The slimes interact in a simple but constrained way: a slime can eat an adjacent slime if it is strictly larger, and upon eating, it grows by the eaten slime’s size.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1923F - Shrink-Reverse

We are given a binary string s of length n and a number k representing the maximum number of allowed operations. Each operation can either swap two characters of the string or remove all leading zeros and then reverse the string.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyhashingimplementationstring-suffix-structuresstrings
CF 1923A - Moving Chips

We are given a row of cells, each either containing a chip or empty. The goal is to move chips leftward into contiguous groups by repeatedly picking a chip and moving it into the closest empty cell to its left.

codeforcescompetitive-programminggreedyimplementation
CF 1923C - Find B

We are given an array c of positive integers and multiple queries asking whether certain subarrays of c are good.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1923B - Monsters Attack!

We have a line with our character at position 0 and monsters positioned at some coordinates $xi$, each with health $ai$. Every second, we can fire up to $k$ bullets, reducing the health of monsters we choose.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1924B - Space Harbour

We have a straight line with n points, each occupied by a ship. Some of these points already host harbours, each with an associated value. A ship at a point incurs a cost if it were to "move" to the next harbour to its right.

codeforcescompetitive-programmingdata-structuresimplementationmathsortings
CF 1924E - Paper Cutting Again

We are asked to model a stochastic process of repeatedly cutting a rectangular sheet of paper and discarding parts of it, and then compute the expected number of steps until its area falls below a threshold.

codeforcescompetitive-programmingcombinatoricsprobabilities
CF 1924F - Anti-Proxy Attendance

I can't write a correct editorial for Codeforces 1924F from the problem statement alone. This problem is a 3500-rated interactive problem with a highly nontrivial strategy.

codeforcescompetitive-programmingconstructive-algorithmsdpinteractiveternary-search
CF 1924C - Fractal Origami

We repeatedly perform the same fold on a square sheet. Every fold takes the current square, folds all four corners to its center, and produces a smaller square whose side length is multiplied by $1/sqrt2$.

codeforcescompetitive-programminggeometrymathmatrices
CF 1924D - Balanced Subsequences

We are working with strings made only from two types of parentheses, and we fix how many opening and closing brackets we must use. Each test case gives three numbers: how many '(' we must place, how many ')' we must place, and a target parameter k.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1924A - Did We Get Everything Covered?

We are given a string s and two integers n and k. Conceptually, we are asked to check if every string of length n that can be built using the first k letters of the alphabet appears somewhere as a subsequence in s.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedyshortest-pathsstrings
CF 1925D - Good Trip

We have a graph on n children. Only m pairs are marked as friends, and each friendship edge has an initial weight f. The teacher performs exactly k excursions. During each excursion, one unordered pair of children is selected uniformly at random from all possible pairs.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilities
CF 1925B - A Balanced Problemset?

We are asked to split an integer $x$ into exactly $n$ positive integers whose sum is $x$, in a way that maximizes the greatest common divisor of these integers. The input gives multiple test cases, each with values for $x$ and $n$.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1926F - Vlad and Avoiding X

We have a fixed $7 times 7$ board whose cells are either black or white. A configuration is considered bad if there exists a black cell whose four diagonal neighbors are also black. Such a pattern looks like an X centered at that cell.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardpimplementation
CF 1926G - Vlad and Trouble at MIT

We are asked to separate music from sleeping students in a dormitory modeled as a tree. Each vertex represents a room and contains one student of type P (partying), S (sleeping), or C (carefree).

codeforcescompetitive-programmingdfs-and-similardpflowsgraphsgreedyimplementationtrees
CF 1926D - Vlad and Division

We are given a set of non-negative integers and asked to partition them into groups so that within each group, no two numbers share a 1-bit in the same position across the first 31 bits.

codeforcescompetitive-programmingbitmasksgreedy
CF 1926E - Vlad and an Odd Ordering

Vladislav has a deck of cards numbered from 1 to n. He wants to arrange them in a sequence with a peculiar rule. First, he takes all odd numbers and lays them out in increasing order. Then he takes all numbers that are twice an odd number and lays them out in increasing order.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresdpimplementationmathnumber-theory
CF 1926C - Vlad and a Sum of Sum of Digits

For every test case, we are given a number n. Vlad writes all integers from 1 through n on the board. Then each integer is replaced by the sum of its decimal digits. The task is to compute $$sum{i=1}^{n} text{digitSum}(i)$$ where digitSum(i) is the sum of the digits of i.

codeforcescompetitive-programmingdpimplementation
Kvant Math Problem 1468

Place the isosceles triangle in coordinates as

kvantmathematicsolympiad
CF 1926A - Vlad and the Best of Five

The task is simple: for each string of length five consisting only of the letters A and B, determine which letter occurs more frequently. Each test case provides one such string, and we have multiple test cases to process.

codeforcescompetitive-programmingimplementation
CF 1926B - Vlad and Shapes

We are given a very small binary image, typically at most 10 by 10 cells. Every cell is either empty or filled. The grid contains exactly one connected geometric figure formed by ones, and that figure is guaranteed to be either a perfect square or a centered triangle (upright…

codeforcescompetitive-programminggeometryimplementation
CF 1927G - Paint Charges

We are given a one-dimensional strip of cells, where each cell contains a “paint charge” with a fixed radius. Activating a charge at position i does not just affect that cell, it paints a contiguous segment either extending left or extending right by exactly a[i] cells…

codeforcescompetitive-programmingdata-structuresdpgreedymath
CF 1927E - Klever Permutation

We need to build a permutation of the numbers from 1 to n such that every contiguous segment of length k has almost the same sum. More precisely, if we compute the sum of every window of length k, the largest and smallest of those sums may differ by at most 1.

codeforcescompetitive-programmingconstructive-algorithmsmathtwo-pointers
CF 1927F - Microcycle

We are asked to find a simple cycle in an undirected, weighted graph where the minimal edge in that cycle is as small as possible. The input is a series of graphs: each graph is described by the number of vertices, the number of edges, and a list of edges with weights.

codeforcescompetitive-programmingdata-structuresdfs-and-similardsugraphsgreedyimplementationsortingstrees
CF 1927D - Find the Different Ones!

The problem gives you an array of integers and a series of queries, each specifying a segment of that array. For each query, you are asked to find two positions within the segment such that the values at these positions are different.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpdsugreedytwo-pointers