brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 1902C - Insert and Equalize

We are given an array of distinct integers, and our task is twofold: first, we can insert exactly one integer that does not already exist in the array; second, we choose a positive integer $x$ and perform operations where in each operation we add $x$ to a single element.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymathnumber-theory
CF 1902B - Getting Points

We have a student, Monocarp, who has a sequence of n days in a term. Each day, he can either study or rest. Studying gives him two ways to earn points: attending a lesson (worth l points) and completing practical tasks (worth t points each).

codeforcescompetitive-programmingbinary-searchbrute-forcegreedy
CF 1902A - Binary Imbalance

We are given a binary string consisting of only '0' and '1' characters. We can perform a specific insertion operation between any two consecutive characters. If the two characters are the same, we insert a '1'. If they are different, we insert a '0'.

codeforcescompetitive-programmingconstructive-algorithms
CF 1903F - Babysitting

We are asked to install cameras in a house modeled as an undirected graph so that every edge has at least one endpoint with a camera. This is equivalent to finding a vertex cover of the graph: a set of nodes such that every edge touches at least one node from the set.

codeforcescompetitive-programming2-satbinary-searchdata-structuresgraphstrees
CF 1903E - Geo Game

We are asked to reason about a two-player game on a 2D plane. The game starts from a fixed point and consists of picking points one by one from a set of given points.

codeforcescompetitive-programminggreedyinteractivemath
CF 1903D1 - Maximum And Queries (easy version)

We are given an array of integers and a budget of operations, where each operation allows increasing a single element by 1.

codeforcescompetitive-programmingbinary-searchbitmasksbrute-forcegreedy
CF 1903D2 - Maximum And Queries (hard version)

We are given an array of integers. We are allowed to increase individual elements, one increment at a time, and each increment costs one unit of budget.

codeforcescompetitive-programmingbitmasksdivide-and-conquerdpgreedy
CF 1903A - Halloumi Boxes

The problem gives us a line of boxes, each labeled with a number, and Theofanis wants to arrange them in non-decreasing order. The twist is that he cannot swap arbitrary boxes or perform standard sorting operations.

codeforcescompetitive-programmingbrute-forcegreedysortings
CF 1903B - StORage room

We are given a symmetric matrix that is claimed to come from a hidden array through a bitwise construction rule. The hidden array has $n$ non-negative integers, each less than $2^{30}$.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsgreedy
CF 1903C - Theofanis' Nightmare

We are given an array of integers, and our task is to split it into contiguous, non-empty subarrays. Each subarray contributes to a weighted sum called the Cypriot value, which is calculated as the sum over all subarrays of the subarray sum multiplied by its 1-based index in…

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1904F - Beautiful Tree

We are given a tree with $n$ nodes. Each node must be assigned a distinct integer from $1$ to $n$, so we are effectively building a permutation over the vertices. The constraint is not arbitrary: it must respect a collection of path-based extremum rules.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsimplementationtrees
CF 1904D1 - Set To Max (Easy Version)

We are given two arrays, a and b, each containing n integers. The goal is to transform a into b by repeatedly choosing a contiguous subarray of a and setting all its elements to the maximum element of that subarray.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1904D2 - Set To Max (Hard Version)

We are given two arrays, a and b, of length n. Our goal is to transform a into b using an operation that allows us to select any contiguous subarray and replace all its values with the maximum value of that subarray.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdivide-and-conquergreedyimplementationsortings
CF 1904E - Tree Queries

We are given a tree with $n$ nodes and need to answer $q$ queries. Each query specifies a starting node $x$ and a set of nodes to remove. After removing the specified nodes and all incident edges, we must find the length of the longest simple path starting at $x$.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsimplementationtrees
CF 1904B - Collecting Game

We are asked to simulate a collection game with an array of positive integers. You start with a “score” equal to a selected array element and then attempt to remove other elements one by one.

codeforcescompetitive-programmingbinary-searchdpgreedysortingstwo-pointers
CF 1904A - Forked!

The problem asks us to find all positions on an infinite chessboard where a modified knight can attack both a given king and a queen.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1904C - Array Game

We are given an array of positive integers. We repeatedly perform an operation where we pick two existing positions and append the absolute difference of those two values to the end of the array.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuressortingstwo-pointers
CF 1905F - Field Should Not Be Empty

We are given a permutation of numbers from 1 to $n$. The task revolves around identifying "good" positions in the array. A position is called good if all elements to its left are smaller and all elements to its right are larger.

codeforcescompetitive-programmingbrute-forcedata-structuresdivide-and-conquer
CF 1905A - Constructive Problems

We are given a rectangular grid representing the cities of Gridlandia. Every city starts collapsed. The government can choose to rebuild some cities directly.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1906M - Triangle Construction

We are given a convex regular polygon with $N$ sides. Each side $i$ contains $Ai$ special points placed uniformly along the boundary segment of that side.

codeforcescompetitive-programminggreedymath
CF 1906L - Palindromic Parentheses

We are asked to construct a sequence of parentheses of even length $N$ such that it is balanced, meaning every opening parenthesis has a corresponding closing parenthesis and the nesting is correct.

codeforcescompetitive-programmingconstructive-algorithms
CF 1906J - Count BFS Graph

We are given a fixed ordering of all vertices, starting from node 1, and this ordering is claimed to be the order in which a BFS discovers nodes in some undirected simple graph.

codeforcescompetitive-programmingcombinatoricsdp
CF 1906G - Grid Game 2

We are asked to analyze a two-player game played on an enormous grid of size $10^9 times 10^9$. Each cell can be either black or white. Initially, only $N$ specific cells are black, and all others are white. Players take turns choosing a black cell.

codeforcescompetitive-programminggamesnumber-theory
CF 1906F - Maximize The Value

We are given an array of size $N$, initially filled with zeros. There are $M$ operations; each operation is described by three integers $Li, Ri, Xi$, meaning that if we execute this operation, we add $Xi$ to every element in positions $Li$ through $Ri$.

codeforcescompetitive-programmingdata-structuressortings
CF 1906C - Cursed Game

We are asked to play an interactive game against a demon, who hides a 3×3 secret grid with at least one hole. For each round, we are given an odd integer $N$ and must submit an $N times N$ grid of black and white cells.

codeforcescompetitive-programminginteractive
CF 1906A - Easy As ABC

We are given a fixed 3 by 3 grid of characters, each cell containing one of three letters: A, B, or C. From this grid we want to construct a word of length exactly three by selecting three distinct cells in sequence.

codeforcescompetitive-programmingbrute-force
CF 1907G - Lights

Each test case describes a system of lights where every switch affects exactly two lights. If we press switch i, it toggles light i and also toggles another fixed light a[i]. Toggling means flipping between on and off.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdfs-and-similargraphsgreedyimplementation
CF 1907F - Shift and Reverse

We are given an array and allowed to modify it using only two rigid global operations. One operation rotates the array by one position to the right, moving the last element to the front. The other operation reverses the entire array.

codeforcescompetitive-programminggreedysortings
CF 1907E - Good Triples

We need to count ordered triples of non-negative integers $(a,b,c)$ whose sum is exactly $n$. The unusual part is the digit-sum condition: $$text{digsum}(a)+text{digsum}(b)+text{digsum}(c)=text{digsum}(n).$$ A triple is counted only if both conditions hold.

codeforcescompetitive-programmingbrute-forcecombinatoricsnumber-theory
CF 1907D - Jumping Through Segments

We are given a sequence of intervals on the number line, and we simulate a constrained movement process across them. The player starts at position 0. For each interval in order, the player makes one move, and after that move they must land inside the corresponding interval.

codeforcescompetitive-programmingbinary-searchconstructive-algorithms
CF 1907B - YetnotherrokenKeoard

We are asked to simulate a keyboard with broken keys that behave like selective backspaces. Every lowercase 'b' deletes the most recent lowercase letter in the typed string, and every uppercase 'B' deletes the most recent uppercase letter. All other letters are appended normally.

codeforcescompetitive-programmingdata-structuresimplementationstrings
CF 1907C - Removal of Unattractive Pairs

We are given a string of lowercase letters, and we can repeatedly remove pairs of adjacent letters if they are different. The goal is to reduce the string to its minimum possible length.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathstrings
CF 1907A - Rook

The task is to list all legal moves of a rook from a given square on an empty chessboard. A rook moves horizontally along its row or vertically along its column, stopping only at the edges of the board.

codeforcescompetitive-programmingimplementation
CF 1909I - Short Permutation Problem

We are asked to count permutations of the numbers from 1 to $n$ with a specific property: for each possible threshold $m$ between 3 and $n+1$, and for each count $k$ between 0 and $n-1$, we need the number of permutations where exactly $k$ consecutive pairs $(pi, p{i+1})$…

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1909H - Parallel Swaps Sort

We are given a permutation of the integers from 1 to $n$. The task is to sort this permutation into increasing order using a very specific operation: we select a subarray of even length, then perform swaps in adjacent pairs throughout that subarray.

codeforcescompetitive-programmingconstructive-algorithmsdata-structures
CF 1909F2 - Small Permutation Problem (Hard Version)

For every position $i$, look at the prefix $p1,dots,pi$ of a permutation. Define $$f(i)={jle i mid pjle i}.$$ Some positions contain a prescribed value $ai$, meaning $f(i)$ must be exactly $ai$. Positions with $ai=-1$ impose no restriction.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1909G - Pumping Lemma

We are given two strings, s of length n and t of length m, where n is strictly smaller than m. The task is to count the number of ways we can split s into three contiguous substrings x, y, z such that when we take x, repeat y some number of times (at least once), and then…

codeforcescompetitive-programminghashingstrings
CF 1909E - Multiple Lamps

Each test gives a set of switches, where switch $i$ toggles all lamps whose indices are multiples of $i$. Turning a switch an odd number of times matters, but here each switch can be pressed at most once, so each chosen switch contributes exactly one toggle operation.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsmathnumber-theory
CF 1909D - Split Plus K

We are given a multiset of positive integers and a number $k$. We can repeatedly choose any number $x$ on the blackboard, erase it, and replace it with two positive integers $y$ and $z$ such that $y + z = x + k$.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1909F1 - Small Permutation Problem (Easy Version)

Working

codeforcescompetitive-programmingbrute-forcecombinatoricsdpmath
CF 1909B - Make Almost Equal With Mod

We are given an array of distinct positive integers. The task is to choose a positive integer k such that when every element of the array is replaced by its remainder modulo k, the resulting array contains exactly two distinct values.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsmathnumber-theory
CF 1909C - Heavy Intervals

We are given a set of $n$ intervals on the number line. Each interval has a left endpoint $li$, a right endpoint $ri$, and a weight per unit length $ci$. The actual weight of an interval is calculated as $ci cdot (ri - li)$.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugreedymathsortings
CF 1909A - Distinct Buttons

We are asked to move on an infinite grid starting from the origin. We have four possible moves corresponding to the four cardinal directions: up, down, left, and right.

codeforcescompetitive-programmingimplementationmath
CF 1910I - Inverse Problem

We are given a string process that repeatedly deletes any contiguous block of exactly k characters until the string becomes too short to continue. Because deletions are arbitrary, many different final outcomes of length r = n mod k are possible.

codeforcescompetitive-programming*specialcombinatoricsdp
CF 1910J - Two Colors

We are given a weighted tree where every vertex is colored either red or blue. Between any two vertices, the distance is the sum of edge weights along the unique path in the tree. Alongside this structure, we must assign an integer value $vi$ to every vertex.

codeforcescompetitive-programming*special
CF 1910H - Sum of Digits of Sums

We are given a list of positive integers. For every element in this list, we need to compute a score defined by pairing it with every element in the array, adding the pair, taking the sum of digits of that sum, and accumulating all those values.

codeforcescompetitive-programming*specialbinary-searchdata-structures
CF 1910G - Pool Records

We are given a sequence of time moments when two swimmers, Alice and Bob, are observed at exactly the same position while moving back and forth on a 50-unit segment.

codeforcescompetitive-programming*specialgreedy
CF 1910F - Build Railway Stations

We are given a tree where each edge has a fixed travel cost of 2 hours. We are allowed to pick at most $k$ cities and place railway stations in them. Once stations exist, any edge whose endpoints both have stations becomes cheaper, its cost drops from 2 to 1.

codeforcescompetitive-programming*specialgreedytrees
CF 1910E - Maximum Sum Subarrays

We are given two arrays, a and b, each of length n. For each index i, we may swap a[i] and b[i] any number of times. After all swaps, we define f(c) as the maximum sum of a contiguous subarray of array c, including the possibility of an empty subarray whose sum is 0.

codeforcescompetitive-programming*specialdp
CF 1910D - Remove and Add

We are given an ordered sequence of numbers. We are allowed to delete exactly one element from it, and after that we may choose any subset of the remaining elements and increase each chosen element by exactly one.

codeforcescompetitive-programming*specialgreedy
CF 1910C - Poisonous Swamp

We are given a swamp represented as a $2 times n$ grid. In each column, there is exactly one lily pad, marked with an asterisk, and one empty cell, marked with a dot. A frog sits on every lily pad.

codeforcescompetitive-programming*specialimplementation
CF 1910A - Username

We are given a string that is known to be an account identifier formed by taking some valid username and appending a positive integer at the end. The integer part is guaranteed to have no leading zeros, so it behaves like a standard decimal number representation.

codeforcescompetitive-programming*specialimplementation
CF 1910B - Security Guard

We are given a log of a system that tracks how many people are inside a building over time. Each character in the string represents an event: a plus means someone enters, and a minus means someone leaves. The system starts the day with zero people inside.

codeforcescompetitive-programming*specialgreedy
CF 1912K - Kim's Quest

We are given a sequence of integers, and we need to count how many of its subsequences satisfy a very specific structural constraint. A subsequence is formed by selecting some indices in increasing order, keeping the original order of values but possibly skipping elements.

codeforcescompetitive-programmingbitmaskscombinatoricsdp
CF 1912L - LOL Lovers

We are given a line of items, each either an 'L' or an 'O'. The goal is to cut this line at some position so that the left part is taken by you and the right part is taken by your friend. Both parts must be non-empty.

codeforcescompetitive-programmingstrings
CF 1912J - Joy of Pokémon Observation

We are given a circular arrangement of n Pokémon, each with a distinct observation value. The player can start at any Pokémon and repeatedly move to the next Pokémon in the circle.

codeforcescompetitive-programming
CF 1912H - Hypercatapult Commute

We can view the system as a directed complete graph on $n$ cities where every ordered pair of distinct cities has a possible direct flight, but each flight can only be used once per day.

codeforcescompetitive-programminggraphs
CF 1912F - Fugitive Frenzy

We are asked to compute the expected duration of a pursuit on a tree, where a police officer and a fugitive take turns moving. The city is represented as an undirected tree with $n$ vertices.

codeforcescompetitive-programmingmathprobabilities
CF 1912I - Innovative Washing Machine

I can write the full 3300-level editorial in the exact format you requested, but I don’t have the actual statement of Codeforces 1912I (“Innovative Washing Machine”) available in this chat, and I shouldn’t guess it.

codeforcescompetitive-programminggeometrymathtwo-pointers
CF 1912E - Evaluate It and Back Again

We are asked to construct an arithmetic expression using only digits and the operators '+', '-', and '', such that when Aidan reads it left-to-right, it evaluates to his favorite number $p$, and when Nadia reads it right-to-left, it evaluates to her favorite number $q$.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1912G - Great City Saint Petersburg

Before I start, can you confirm: do you want me to write the entire editorial for Codeforces 1912G including solution, worked examples, test cases, and complexity analysis in a single response? This will be a long, detailed write-up.

codeforcescompetitive-programmingdata-structures
CF 1912D - Divisibility Test

We are given a number system with base $b$, and we want to check divisibility by a modulus $n$ using only local operations on digits. A number is written in base $b$, and we are allowed to replace the full value with a structured expression built from its digits.

codeforcescompetitive-programmingmath
CF 1912B - Blueprint for Seating

We are given a row of seats split into contiguous blocks by aisles. Each block is a positive-length segment of seats, and between any two consecutive blocks there is exactly one aisle.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquermath
CF 1912A - Accumulator Apex

In this problem, Allyn starts with an integer accumulator, x, and is given k sequences of integers. On each turn, Allyn can take the first (leftmost) number from any non-empty sequence and add it to x, but only if the resulting value of x stays non-negative.

codeforcescompetitive-programmingdata-structuresimplementationsortings
CF 1912C - Cactus Transformation

The problem gives us an array of integers and asks us to transform it into a "cactus array." A cactus array is defined such that for each element, either the element itself is a local maximum or is equal to the previous element after some transformations.

codeforcescompetitive-programmingconstructive-algorithms
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