brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1994F - Stardew Valley

Codeforces 1994F: Stardew Valley

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstrees
CF 1994E - Wooden Game

We are given several independent forests, where each forest consists of multiple rooted trees. Every tree has a fixed root at vertex 1, and each vertex defines a natural subtree consisting of itself and all descendants in this rooted structure.

codeforcescompetitive-programmingbitmasksgreedymathtrees
CF 1994B - Fun Game

We are given two binary sequences of equal length, s and t. Vanya can perform a specific operation on s repeatedly: he chooses a contiguous subarray from position l to r, and for each position i in that subarray, replaces s[i] with s[i] XOR s[i - l + 1].

codeforcescompetitive-programmingbitmasksconstructive-algorithmsgreedymath
CF 1994A - Diverse Game

We are given a grid that already contains every integer from 1 to $n cdot m$ exactly once, arranged in some arbitrary order. The task is to construct another grid of the same dimensions using the same set of numbers such that no number stays in its original cell.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1994D - Funny Game

We are asked to construct a connected graph on $n$ vertices, starting from an empty graph, by performing $n-1$ operations. Each operation is numbered from 1 to $n-1$.

codeforcescompetitive-programmingconstructive-algorithmsdsugraphsgreedymathnumber-theorytrees
CF 1994C - Hungry Games

We are given a row of values, and we want to count how many contiguous segments behave “well” under a very specific simulation rule. When we pick a segment $[l, r]$, we process its elements from left to right, maintaining a running sum $g$.

codeforcescompetitive-programmingbinary-searchdptwo-pointers
CF 1987G2 - Spinning Round (Hard Version)

We are given a permutation of integers from 1 to $n$ and a string of instructions of length $n$, where each instruction is either L, R, or ?. Each position in the permutation can either connect to its nearest larger number to the left (L) or to the right (R), and ?

codeforcescompetitive-programmingdivide-and-conquerdptrees
CF 1987H - Fumo Temple

We are asked to find a hidden cell in a rectangular matrix of size $n times m$, where each cell contains either -1, 0, or 1.

codeforcescompetitive-programminginteractive
CF 1987G1 - Spinning Round (Easy Version)

We are given a permutation p of length n and a string s of the same length consisting only of ?. Each position i in the permutation defines two special indices: li is the last index before i where the permutation value is larger, and ri is the first index after i where the…

codeforcescompetitive-programmingdivide-and-conquerdptrees
CF 1987B - K-Sort

We are given an array of integers representing a sequence of numbers that we want to make non-decreasing. The only operation allowed is to choose a set of k indices and increment each of those selected elements by one, paying k + 1 coins for the operation.

codeforcescompetitive-programminggreedy
CF 1987D - World is Mine

We have a two-player game between Alice and Bob played over a set of cakes, each with an integer tastiness. Alice goes first.

codeforcescompetitive-programmingdpgames
CF 1987F2 - Interesting Problem (Hard Version)

We are given an array of integers where each element lies between 1 and the array's length. The operation we can perform requires finding an index i such that the value at that position equals i. When we do, we remove both a[i] and the following element a[i+1] from the array.

codeforcescompetitive-programmingdp
CF 1987F1 - Interesting Problem (Easy Version)

We are given an array of integers of length $n$. At each step, we can choose an index $i$ where $ai = i$ and $i < n$, and remove both $ai$ and $a{i+1}$. The goal is to maximize the number of times we can perform this operation until no more valid indices exist.

codeforcescompetitive-programmingdp
CF 1987A - Upload More RAM

We are asked to determine the minimum time required to upload a certain amount of RAM, measured in gigabytes. You can upload either 0 or 1 GB per second, but there is a constraint on the network: in any consecutive block of $k$ seconds, the total upload cannot exceed 1 GB.

codeforcescompetitive-programminggreedymath
CF 1972E - Fenwick Tree

The problem asks us to reverse-engineer a Fenwick tree, or binary indexed tree, operation. A Fenwick tree s is derived from an array a by summing a specific range for each index k.

codeforcescompetitive-programmingcombinatoricsdata-structuresmathmatrices
CF 1972C - Permutation Counting

We are given a multiset of cards, each labeled with an integer from 1 to $n$, and for each type $i$ we know how many cards $ai$ we already own. We also have $k$ coins to buy additional cards, and the shop has unlimited supply of each type.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyimplementationmathsortings
CF 1972F - Long Way to be Non-decreasing

Connection interrupted. Waiting for the complete answer

codeforcescompetitive-programmingbinary-searchdfs-and-similargraphsimplementation
CF 1972B - Coin Games

We are given a circular arrangement of coins. Each coin is either facing up or facing down. Two players alternate turns, and on each turn a player must pick one coin that is currently facing up, remove it, and then flip its two neighbors.

codeforcescompetitive-programminggames
Kvant Math Problem 1527

We shall prove that the only integer $n>3$ for which a configuration of points $A_1,\dots,A_n$ and real numbers $r_1,\dots,r_n$ satisfying the problem conditions exists is

kvantmathematicsolympiad
CF 1972D2 - Reverse Card (Hard Version)

We are asked to count ordered pairs of positive integers (a, b) such that 1 ≤ a ≤ n and 1 ≤ b ≤ m, with an additional divisibility condition: b gcd(a, b) must be divisible by a + b.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1972D1 - Reverse Card (Easy Version)

We are asked to count how many ordered pairs of integers $(a, b)$ satisfy a divisibility condition under bounded ranges. For each test case, we are given two limits $n$ and $m$.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1966F - Missing Subarray Sum

We are asked to reconstruct a hidden array of positive integers that is a palindrome, given nearly all of its subarray sums. Each subarray sum corresponds to the sum of a contiguous segment of the array, and exactly one subarray sum is missing.

codeforcescompetitive-programmingconstructive-algorithms
CF 1966D - Missing Subsequence Sum

The task is to construct a small sequence of non-negative integers such that every sum from 1 to $n$, except a single forbidden value $k$, can be represented as the sum of some subsequence.

codeforcescompetitive-programmingconstructive-algorithmsgreedymathnumber-theory
CF 1966A - Card Exchange

We are given a hand of cards, each labeled with a number, and a fixed integer $k$. The operation allowed is to take any $k$ identical cards and exchange them for $k-1$ cards of any number we choose. The goal is to reduce the total number of cards as much as possible.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 1966E - Folding Strip

We are given a binary string representing a strip of paper with 0s and 1s. We can fold the strip at any position between adjacent characters.

codeforcescompetitive-programminggreedyimplementation
CF 1966C - Everything Nim

We are asked to analyze a two-player game with multiple piles of stones. On a player's turn, they choose a number $k$ that does not exceed the smallest non-empty pile, then remove $k$ stones from every pile that still has stones.

codeforcescompetitive-programminggamesgreedy
CF 1966B - Rectangle Filling

We are given a grid of size $n times m$ filled with black and white tiles. Each tile is either 'B' (black) or 'W' (white). The task is to determine whether it is possible, using a series of rectangle-filling operations, to make all tiles in the grid the same color.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1944F2 - Counting Is Fun (Hard Version)

We are asked to count arrays of length n with elements between 0 and k that can be reduced to all zeros using a specific operation. The operation allows selecting two distinct indices l and r and subtracting 1 from all elements between l and r inclusive.

codeforcescompetitive-programmingcombinatoricsdp
CF 1944F1 - Counting Is Fun (Easy Version)

We are given an array of length $n$, where each position can independently take any value from $0$ to $k$. So the total universe is all $(k+1)^n$ arrays. The question is not about simulating the process directly.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1944C - MEX Game 1

Alice and Bob play on a multiset of numbers. Alice and Bob alternately remove elements from the array, with Alice moving first. The difference is that whenever Alice removes a value, she also keeps it in her personal array c, while Bob simply deletes a value.

codeforcescompetitive-programmingconstructive-algorithmsgamesgreedy
CF 1944E - Tree Compass

We are asked to color all nodes of a tree black using the fewest operations. Each operation lets us pick a node $v$ and a distance $d$, and it colors all nodes that are exactly distance $d$ from $v$.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargreedytrees
CF 1944B - Equal XOR

This is a Type A problem: find all natural numbers $x$ satisfying a given condition. For a Type A problem, the solution must do two things: 1. Derive necessary conditions and prove that every solution must satisfy them. 2.

codeforcescompetitive-programmingbitmasksconstructive-algorithms
CF 1944D - Non-Palindromic Substring

We are given a string of lowercase English letters and a set of queries, each specifying a contiguous substring of the string. For each query, we are asked to compute the sum of all lengths $k$ for which there exists at least one substring of length $k$ that is not a palindrome.

codeforcescompetitive-programminghashingimplementationstrings
CF 1937F - Bitwise Paradox

We are given two integer arrays, a and b, of length n, along with a fixed integer v. We are asked to process queries of two types. The first type updates a single element in b.

codeforcescompetitive-programmingdata-structurestwo-pointers
CF 1937B - Binary Path

We have a grid with exactly two rows and n columns. Every cell contains either 0 or 1. The path always starts at the top-left cell and ends at the bottom-right cell.

codeforcescompetitive-programmingdpgreedyimplementation
CF 1937E - Pokémon Arena

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

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

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

codeforcescompetitive-programmingbitmasksconstructive-algorithmsinteractive
CF 1937D - Pinball

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

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

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

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

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

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

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

codeforcescompetitive-programmingdata-structuresdptrees
CF 1930B - Permutation Printing

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

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

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

codeforcescompetitive-programmingbrute-forcedpgreedystrings
CF 1930C - Lexicographically Largest

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

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

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

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

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

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

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

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

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

codeforcescompetitive-programmingcombinatoricsdpmathtrees
CF 1929B - Sasha and the Drawing

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

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1925F - Fractal Origami

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

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

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

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

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

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1925E - Space Harbour

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

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 1917E - Construct Matrix

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

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1917A - Least Product

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

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

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

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

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

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

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

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

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

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

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

codeforcescompetitive-programminggraph-matchings
CF 1906H - Twin Friends

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

codeforcescompetitive-programmingcombinatoricsdp
CF 1906E - Merge Not Sort

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

codeforcescompetitive-programmingconstructive-algorithmsdp
CF 1906B - Button Pressing

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

codeforcescompetitive-programmingbitmasksconstructive-algorithmshashing
CF 1905C - Largest Subsequence

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

codeforcescompetitive-programminggreedystrings
CF 1905E - One-X

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

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

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

codeforcescompetitive-programminggreedytrees
CF 1905D - Cyclic MEX

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

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

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

codeforcescompetitive-programmingimplementationstrings
CF 1894E - Freedom of Choice

Working

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

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

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

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

codeforcescompetitive-programmingconstructive-algorithms
CF 1894C - Anonymous Informant

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

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

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

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

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

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

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

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

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

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

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

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

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

codeforcescompetitive-programmingcombinatoricsdsu
CF 1877G - Ball-Stackable

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

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

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

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 1877C - Joyboard

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

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

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

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

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

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

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

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

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

codeforcescompetitive-programmingdpgraphsgreedymathprobabilities
CF 1875A - Jellyfish and Undertale

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

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

Codeforces 1875E: Jellyfish and Math

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

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

codeforcescompetitive-programmingdp
CF 1875B - Jellyfish and Game

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

codeforcescompetitive-programmingbrute-forcegreedyimplementation
CF 1869E - Travel Plan

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

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1869F - Flower-like Pseudotree

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

codeforcescompetitive-programmingconstructive-algorithms
CF 1862A - Gift Carpet

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

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 1857G - Counting Graphs

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

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdsugraphsgreedysortingstrees