brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1523D - Love-Hate

We are given a set of n friends, each with their own preferences over m currencies. Each friend likes at most p currencies, so the like-lists are sparse. The goal is to find the largest set of currencies such that at least half of the friends like all the currencies in that set.

codeforcescompetitive-programmingbitmasksbrute-forcedpprobabilities
CF 1523C - Compression and Expansion

We are given a sequence of integers, each representing the last number of a nested list item after William accidentally erased everything else. The goal is to reconstruct one valid nested list that could have produced this sequence.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementationtrees
CF 1525A - Potion-making

We are tasked with creating a potion that contains exactly $k%$ magic essence and $(100-k)%$ water. The cauldron starts empty, and we can only add one liter at a time of either ingredient.

codeforcescompetitive-programmingmathnumber-theory
CF 1525F - Goblins And Gnomes

The city is a directed acyclic graph. The statement guarantees that once a goblin leaves a hall, it can never come back, which is exactly the definition of a DAG. During wave i, exactly i goblins appear. Each goblin chooses a directed path.

codeforcescompetitive-programmingbrute-forcedpflowsgraph-matchings
CF 1525E - Assimilation IV

Monocarp has an empire of n cities and wants to control m points on a map. Each city can build one Monument. When a Monument is built, it controls all points within a distance that grows by 1 each turn.

codeforcescompetitive-programmingcombinatoricsdpmathprobabilitiestwo-pointers
CF 1525D - Armchairs

We have a row of n armchairs, some of which are initially occupied by people. Our goal is to move every person to a currently empty armchair in such a way that all initially occupied seats become free.

codeforcescompetitive-programmingdpflowsgraph-matchingsgreedy
CF 1525C - Robot Collisions

We have a set of robots moving along a one-dimensional line segment from 0 to $m$. Each robot starts at a distinct integer position between 0 and $m$ and moves either left or right at a constant speed of 1 unit per second.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortings
CF 1525B - Permutation Sort

We are given a permutation of the numbers from 1 to n. In one operation, we may choose any contiguous segment of the array and rearrange the elements inside that segment however we like. The only restriction is that the chosen segment cannot be the entire array.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1526F - Median Queries

We are given a hidden permutation of the numbers from 1 to n. The permutation is fixed, but we never see it directly. Instead, we can only interact with it through a query on three indices.

codeforcescompetitive-programmingconstructive-algorithmsinteractiveprobabilities
CF 1526D - Kill Anton

We are asked to take a string composed only of the characters "A", "N", "T", and "O" and find a permutation of it that maximizes the number of adjacent swaps required to revert it back to the original string.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsdata-structuresmathstrings
CF 1526E - Oolimry and Suffix Array

We are given a permutation representing the suffix array of some unknown string of length $n$ over an alphabet of size $k$. Each element $si$ of this array tells us which starting index corresponds to the $i$-th lexicographically smallest suffix.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1526C2 - Potions (Hard Version)

We are walking along a row of potions, starting at the first and moving to the last. Each potion has a value: positive values increase your health, negative values decrease it. At each potion, you can choose to drink it or skip it, but your health must never drop below zero.

codeforcescompetitive-programmingdata-structuresgreedy
CF 1526A - Mean Inequality

Let a multiplication algorithm be called online if it produces the $(k+1)$st output bit of the product $uv$, starting from the least significant bit, only after reading the first $k+1$ input bits of each operand, also from least significant to most significant.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 1526B - I Hate 1111

Every allowed number has a very special form: $$11, 111, 1111, 11111,dots$$ For each query, we are given a target value $x$, and we must determine whether it can be represented as a sum of these numbers, with unlimited reuse of each value.

codeforcescompetitive-programmingdpmathnumber-theory
CF 1526C1 - Potions (Easy Version)

We have a sequence of potions lined up, each changing our health by some integer value, which can be positive or negative. We start with zero health and move from the first potion to the last.

codeforcescompetitive-programmingbrute-forcedata-structuresdpgreedy
CF 1527D - MEX Tree

We have a tree whose vertices are labeled with the integers 0 through n - 1. For every unordered pair of distinct vertices (u, v), we look at the unique simple path connecting them.

codeforcescompetitive-programmingcombinatoricsdfs-and-similarimplementationmathtrees
CF 1527E - Partition Game

Let a multiplication algorithm be called online if it produces the $(k+1)$st output bit of the product $uv$, starting from the least significant bit, only after reading the first $k+1$ input bits of each operand, also from least significant to most significant.

codeforcescompetitive-programmingbinary-searchdata-structuresdivide-and-conquerdp
CF 1527C - Sequence Pair Weight

We are given several arrays, and for each array we consider every possible contiguous subarray. For each subarray, we define its “weight” as the number of pairs of positions inside it that contain the same value.

codeforcescompetitive-programminghashingimplementationmath
CF 1527A - And Then There Were K

Let a multiplication algorithm be called online if it produces the $(k+1)$st output bit of the product $uv$, starting from the least significant bit, only after reading the first $k+1$ input bits of each operand, also from least significant to most significant.

codeforcescompetitive-programmingbitmasks
CF 1527B2 - Palindrome Game (hard version)

We are given a binary string and two players, Alice and Bob, who alternately modify it. A move can either change a single '0' into '1' at a cost of one dollar, or reverse the entire string for free.

codeforcescompetitive-programmingconstructive-algorithmsgames
CF 1527B1 - Palindrome Game (easy version)

We are given a binary string that is already symmetric from both ends. The game starts with Alice and Bob alternating turns, and the only thing that matters financially is how many times each player is forced to flip a character from 0 to 1, since each such flip costs one dollar.

codeforcescompetitive-programmingconstructive-algorithmsgames
CF 1528B - Kavi on Pairing Duty

We are asked to count the number of ways to pair $2n$ points arranged on a straight line such that every pair of segments either has one segment fully inside the other or both segments are of equal length.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1528F - AmShZ Farm

The problem defines a special class of arrays of length $n$ whose entries lie in $[1,n]$. Such an array is called “more-equal” if we can increase each element independently by some non-negative amount so that the resulting array becomes a permutation of $1..n$.

codeforcescompetitive-programmingcombinatoricsfftmath
Kvant Math Problem 114

The circle contains numbers $x_1,\dots,x_n$ in cyclic order.

kvantmathematicsolympiad
CF 1528E - Mashtali and Hagh Trees

We are asked to count the number of different unlabeled Hagh trees of a given height $n$. A Hagh tree is a rooted directed tree with three key properties: its longest directed path has length exactly $n$, every vertex has degree at most three, and any pair of vertices that are…

codeforcescompetitive-programmingcombinatoricsdptrees
CF 1528D - It's a bird! No, it's a plane! No, it's AaParsa!

We are asked to compute the shortest travel times between all pairs of cities in a land with $n$ cities, where each city contains at least one transport cannon.

codeforcescompetitive-programmingconstructive-algorithmsgraphsshortest-paths
CF 1528C - Trees of Tranquillity

We are given two rooted trees on the same set of vertices 1..n. Both trees are rooted at vertex 1. From these two trees we define a graph. Two vertices are connected if they satisfy two conditions simultaneously.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
CF 1528A - Parsa's Humongous Tree

We are given a tree with n vertices. On each vertex, there is a range [lv, rv] of integers that can be assigned. We need to assign a number av to each vertex within its range so that the sum of absolute differences along all edges is maximized.

codeforcescompetitive-programmingdfs-and-similardivide-and-conquerdpgreedytrees
CF 1529A - Eshag Loves Big Arrays

Let $U(x)$ and $V(x)$ be polynomials of degree $r$ with integer coefficients, and let $W(x) = U(x)V(x),$ so $W(x)$ has degree at most $2r$. Write $U(x) = sum{i=0}^{r} Ui x^i, qquad V(x) = sum{i=0}^{r} Vi x^i, qquad W(x) = sum{k=0}^{2r} Wk x^k.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1529B - Sifid and Strange Subsequences

We are given multiple arrays, and for each one we want to select a subsequence that satisfies a very strong internal constraint.

codeforcescompetitive-programminggreedymathsortings
CF 1530F - Bingo

We are asked to compute the probability that a square table of events is "winning." Each cell of an $n times n$ table contains an event that may happen with a given probability. Rows, columns, the main diagonal, and the antidiagonal are considered lines.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmathprobabilities
CF 1530H - Turing's Award

We are given a permutation of numbers from 1 to n. A token starts at position 0 on an infinite integer line. Over time, each value of the permutation is written on

codeforcescompetitive-programmingdata-structuresdp
CF 1530E - Minimax

The solution is attempting to justify formula (25) via polynomial interpolation of the product polynomial values.

codeforcescompetitive-programmingconstructive-algorithmsgreedystrings
CF 1530G - What a Reversal

We are given two binary strings, a and b, of the same length n and an integer k. Our goal is to transform a into b by repeatedly reversing substrings of a that contain exactly k ones. Each reversal can involve any number of zeros.

codeforcescompetitive-programmingconstructive-algorithms
Kvant Math Problem 1121

Let $C'$ be the reflection of $C$ across the line $AB$, and let $A'$ be the reflection of $A$ across the line $BC$.

kvantmathematicsolympiad
CF 1530D - Secret Santa

We are asked to construct a permutation-like assignment for a group of people. Each person must give a gift to exactly one other person, and no one is allowed to give a gift to themselves.

codeforcescompetitive-programmingconstructive-algorithmsflowsgraphsgreedymath
CF 1530B - Putting Plates

We are asked to maximize the number of plates on a rectangular table, represented as an $h times w$ grid. Plates can only be placed along the perimeter, which includes the first row, last row, first column, and last column.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1530A - Binary Decimal

The problem asks us to break a positive integer $n$ into a sum of numbers whose decimal digits are only 0 or 1. These numbers are called binary decimals, like 1, 10, 11, 101, 1000. The goal is to determine the smallest number of such binary decimals that sum up to $n$.

codeforcescompetitive-programminggreedymath
CF 1530C - Pursuit

We have a contest with multiple stages, each stage giving between 0 and 100 points. You and Ilya have already completed n stages, and we know the scores for both of you.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedysortings
CF 1531E2 - Сортировка слиянием

We are given a string consisting of 0s and 1s, which represents the sequence of decisions made during the merge steps of a merge sort on some permutation of integers from 1 to n.

codeforcescompetitive-programming*specialbrute-force
CF 1531D - Редактируем Зингер | color

We have a chronological list of bot messages. The bot keeps two pieces of state. The first is whether color changes are currently locked. The second is the current dome color, one of seven rainbow colors. Initially the dome is blue and color changes are unlocked.

codeforcescompetitive-programming*special
CF 1531C - Симметричный амфитеатр

We are asked to design a side-view schematic of an amphitheater built from exactly n identical squares. The layout must form a staircase structure, meaning a sequence of towers with heights that do not increase from left to right.

codeforcescompetitive-programming*specialconstructive-algorithmsdp
CF 1531E1 - Сортировка слиянием

The merge sort code in the statement does not only sort an array, it also records the sequence of decisions taken during every comparison while merging two sorted halves.

codeforcescompetitive-programming*special
CF 1531B1 - Мониторинг

We are given a collection of monitors, each with a width and a height. We want to count how many unordered pairs of distinct monitors can be rotated so that their heights match. Rotating a monitor swaps its width and height.

codeforcescompetitive-programming*special
CF 1531A - Зингер | color

We need to simulate the behavior of a chatbot that controls the illumination color of the Singer House dome. Initially, the dome is colored blue, and color changes are allowed. The bot receives a sequence of messages.

codeforcescompetitive-programming*specialimplementation
CF 1531B2 - Мониторинг

We are given a set of monitors, each with a width and height, and we can rotate any monitor by 90 degrees. Our goal is to count the number of distinct unordered pairs of monitors such that after potentially rotating either or both, their heights match.

codeforcescompetitive-programming*special
Kvant Math Problem 1101

Let $ABC$ be an isosceles triangle with $AB=AC=s$ and $BC=b$.

kvantmathematicsolympiad
CF 1532D - Teams Forming

We are given an even number of students, each with a programming skill level. The goal is to form exactly $n/2$ teams, each containing two students. A team is valid only if both students have the same skill level.

codeforcescompetitive-programming*specialsortings
Kvant Math Problem 1076

Let $ABC$ be an acute triangle.

kvantmathematicsolympiad
CF 1533J - Pawns

We are given an infinite chessboard with black pawns placed at certain integer coordinates. Our goal is to capture all black pawns using as few white pawns as possible.

codeforcescompetitive-programming*special
CF 1533F - Binary String Partition

We are given a binary string. For a fixed value of $k$, a substring is considered valid if at least one of the two character counts is small: either it contains at most $k$ zeroes or at most $k$ ones.

codeforcescompetitive-programming*specialbinary-searchgreedy
CF 1533E - Chess Team Forming

We are tasked with forming a chess team by adding one final player to Polycarp's existing roster of $n$ members. Each player's strength is an integer, and the opposing team already has $n+1$ members.

codeforcescompetitive-programming*specialbinary-searchdata-structuresgreedy
Kvant Math Problem 1043

A partition of $\mathbb{Z}$ into three subsets is encoded by a function $f:\mathbb{Z}\to\mathbb{Z}_3$.

kvantmathematicsolympiad
CF 1534G - A New Beginning

The claimed output 10 for "0?10" is actually impossible. There are only 10 total substrings of a length-4 string, and two of them are not beautiful: - "0?10" cannot be made alternating. - "?10" cannot be made alternating. So the correct answer is 8.

codeforcescompetitive-programmingdata-structuresdpgeometrysortings
Kvant Math Problem 1029

Let the arithmetic progression be

kvantmathematicsolympiad
IMO 1972 Problem 5

The correction cannot rely on supremum arguments or derived proportionality identities because those depend on unjustified global structure of $f$ and $g$.

imomathematicsolympiad
CF 1534H - Lost Nodes

Consider a closed container of fixed volume $V$ containing an ideal gas whose bulk temperature is $T1$. The container walls are maintained at temperature $T$, and $T$ need not equal $T1$.

codeforcescompetitive-programmingconstructive-algorithmsdpgraphsinteractivesortingstrees
CF 1534F2 - Falling Sand (Hard Version)

We are given a grid representing a vertical board filled with sand blocks. Each cell either contains a block or is empty. There are also target requirements per column: for every column, we want at least a certain number of sand blocks to end up in a counter at the bottom.

codeforcescompetitive-programmingdfs-and-similardpgraphsgreedy
CF 1534B - Histogram Ugliness

We are given a histogram represented as an array of integers, where each integer is the height of a vertical bar. Little Dormi can decrease the height of any bar by one repeatedly, and each such decrease counts as an operation.

codeforcescompetitive-programminggreedyimplementationmath
CF 1534D - Lost Tree

We are asked to reconstruct an unweighted tree given a limited interactive query mechanism. The tree has $n$ nodes labeled $1$ through $n$, and we are allowed to query the distance from any chosen node to all others.

codeforcescompetitive-programmingconstructive-algorithmsinteractivetrees
CF 1534F1 - Falling Sand (Easy Version)

We are given a grid of n rows and m columns where each cell either contains a sand block () or is empty (.). Alongside the grid, we are given an array a of length m. In this easy version of the problem, each a[i] exactly equals the number of sand blocks in column i.

codeforcescompetitive-programmingdfs-and-similargraphsgreedy
CF 1534E - Lost Array

We are given a hidden array of length n. We cannot see its elements directly, but we are allowed to ask queries. Each query chooses exactly k distinct positions, and the system returns the XOR of the values at those positions.

codeforcescompetitive-programminggraphsgreedyinteractiveshortest-paths
CF 1534C - Little Alawn's Puzzle

We are given a 2 by n grid where each row is a permutation of numbers from 1 to n. So every number appears exactly once in each row, and every column contains two distinct values. The only operation allowed is swapping the two values inside any column.

codeforcescompetitive-programmingcombinatoricsdpdsugraphsmath
CF 1534A - Colour the Flag

The claimed output 10 for "0?10" is actually impossible. There are only 10 total substrings of a length-4 string, and two of them are not beautiful: - "0?10" cannot be made alternating. - "?10" cannot be made alternating. So the correct answer is 8.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1535C - Unstable String

We are given a string containing '0', '1', and '?'. A substring is considered beautiful if we can replace every '?' independently with either 0 or 1 so that the resulting substring becomes an alternating binary string. In other words, neighboring characters must always differ.

codeforcescompetitive-programmingbinary-searchdpgreedyimplementationstringstwo-pointers
CF 1535F - String Distance

We are given a collection of strings of equal length, and our task is to quantify how "sortable into each other" they are using a specific operation. This operation allows us to take any contiguous substring in one string and sort its characters in ascending order.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structureshashingimplementationstrings
CF 1535E - Gold Transfer

I see what is happening. The actual output is empty. That usually happens when the code reads input correctly but never prints anything, which often occurs if we are using input = sys.stdin.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedyinteractivetrees
CF 1535A - Fair Playoff

We have a mini playoff tournament with exactly four players. The first two face off, the last two face off, and the winners meet in the final. Each player has a unique skill value, and in any match the higher-skilled player always wins.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1535D - Playoff Tournament

The proposed solution does not answer the exercise at all. Exercise 4.3.2.7 asks for a derivation of an alternative form of equation (24) in the Chinese remainder conversion algorithm, followed by a discussion of the computational advantages and disadvantages of storing the…

codeforcescompetitive-programmingdata-structuresdfs-and-similardpimplementationtrees
CF 1535B - Array Reodering

We are given an array of integers and may permute it however we like. After choosing an ordering, a pair of positions $(i,j)$ with $i<j$ is called good if $$gcd(ai, 2aj) 1.$$ The task is to maximize the number of good pairs. The input contains multiple test cases.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theorysortings
CF 1536F - Omkar and Akmar

We are asked to count all possible distinct games played on a circular board with $n$ cells, where two players take turns placing letters A or B. Akmar moves first. A letter cannot be placed adjacent to a cell that already contains the same letter.

codeforcescompetitive-programmingchinese-remainder-theoremcombinatoricsconstructive-algorithmsfftgamesgeometrymathmeet-in-the-middlestring-suffix-structures
CF 1537B - Bad Boy

We are asked to place two yo-yos in a rectangular room to maximize the total Manhattan distance Anton must travel to pick them both up and return to his starting position. The room is an $n times m$ grid, and Anton starts at cell $(i, j)$.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1537F - Figure Fixing

We are given a connected undirected graph where each node has an initial value and a target value. We can pick any edge and add the same integer to both endpoints.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsugraphsgreedymath
CF 1537E2 - Erase and Extend (Hard Version)

Codeforces 1537E2: Erase and Extend (Hard Version)

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyhashingstring-suffix-structuresstringstwo-pointers
CF 1537E1 - Erase and Extend (Easy Version)

We are given a string s of length n and a target length k. Our goal is to construct a string of length exactly k by performing two operations any number of times: removing the last character of the current string, or duplicating the string by concatenating it with itself.

codeforcescompetitive-programmingbinary-searchbrute-forcedpgreedyhashingimplementationstring-suffix-structuresstringstwo-pointers
CF 1537C - Challenging Cliffs

We are given a multiset of mountain heights and must arrange them into a sequence. The optimization happens in two layers. First, among all possible permutations, we want the first and last heights to be as close as possible.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementationmath
CF 1537D - Deleting Divisors

We start with a positive integer $n$. Two players alternate turns, with Alice moving first. On each turn, the current player chooses a proper divisor of the current number, meaning a divisor that is neither $1$ nor the number itself, and subtracts it from the number.

codeforcescompetitive-programminggamesmathnumber-theory
CF 1537A - Arithmetic Array

We are given an integer array, and our task is to make its arithmetic mean equal to one by appending non-negative integers. Each test case presents an array of arbitrary integers, both positive and negative, and asks for the minimal number of additions needed.

codeforcescompetitive-programminggreedymath
CF 1538G - Gift Set

We have two piles of candies. One pile contains x red candies and the other contains y blue candies. Each gift set must use exactly a + b candies. There are two possible compositions: - a red and b blue - b red and a blue The two types are symmetric.

codeforcescompetitive-programmingbinary-searchgreedymathternary-search
CF 1538C - Number of Pairs

We are given an array of integers and a range defined by two values, l and r. The task is to count all pairs of distinct indices (i, j) such that the sum of the elements at these indices lies within the given range, including the boundaries.

codeforcescompetitive-programmingbinary-searchdata-structuresmathtwo-pointers
CF 1538B - Friends and Candies

We are given an array of integers representing how many candies each person initially holds. In a single operation, we are allowed to pick some subset of people, take all candies from them, and then freely redistribute those candies across everyone.

codeforcescompetitive-programminggreedymath
CF 1539F - Strange Array

The solution attempts to prove the lower bound on the true remainder when the trial quotient $hat q$ underestimates the true quotient $q$ by 1. It correctly identifies that $hat q = q-1$ under the hypotheses and expresses the true remainder as $r = hat r - v$.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 1539E - Game with Cards

Represent each integer in base $b$ as a doubly linked list of digits $$(v{n-1}, v{n-2}, dots, v0),$$ where each node contains one digit $vi in {0, dots, b-1}$, together with pointers $$text{left}(i), text{right}(i)$$ to adjacent digits.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresdpgreedyimplementation
CF 1539C - Stable Groups

We are given the skill levels of students. A group is considered stable if, after sorting the students inside that group, every adjacent pair differs by at most x.

codeforcescompetitive-programminggreedysortings
CF 1539B - Love Song

We are given a lowercase string representing the song and many queries on contiguous substrings of that string. Each letter contributes a value equal to its position in the alphabet. For example, a = 1, b = 2, c = 3, and so on.

codeforcescompetitive-programmingdpimplementationstrings
CF 1539D - PriceFixed

We are asked to determine the minimal total cost for Lena to buy a set of products where each product has a required quantity and a threshold for a discount.

codeforcescompetitive-programmingbinary-searchgreedyimplementationsortingstwo-pointers
CF 1539A - Contest Start

Represent each integer in base $b$ as a doubly linked list of digits $$(v{n-1}, v{n-2}, dots, v0),$$ where each node contains one digit $vi in {0, dots, b-1}$, together with pointers $$text{left}(i), text{right}(i)$$ to adjacent digits.

codeforcescompetitive-programmingcombinatoricsgeometrygreedymath
CF 1540D - Inverse Inversions

The array $b$ is not arbitrary. For every position $i$, $bi$ tells us how many earlier elements of the permutation are larger than $pi$.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structures
CF 1540E - Tasty Dishes

We are given a small directed system of chefs, where each chef holds a value. The structure is acyclic in the sense that chef $i$ can only interact with chefs of higher index. This allows information to flow only from right to left.

codeforcescompetitive-programmingmathmatrices
CF 1540C1 - Converging Array (Easy Version)

The operation acts on a neighboring pair. Let $$di=a{i+1}-ai.$$ If $dige bi$, the operation changes nothing. If $di<bi$, both values are replaced by numbers with the same sum and with difference exactly $bi$.

codeforcescompetitive-programmingdpmath
CF 1540B - Tree Array

We are asked to calculate the expected number of inversions in a random process of marking nodes in a tree. The tree has n nodes, and the marking process begins with a uniformly random initial node.

codeforcescompetitive-programmingbrute-forcecombinatoricsdpgraphsmathprobabilitiestrees
CF 1540A - Great Graphs

We are given a farm with $n$ pastures and one-way roads between them. Each road has a travel time, which can be negative. Farmer John remembers only the shortest travel times from pasture 1 to every other pasture.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyshortest-pathssortings
CF 1541A - Pretty Permutations

We are asked to reorder a sequence of cats standing in a line so that no cat remains in its original position, while also minimizing the total distance each cat moves. The input consists of several test cases, each specifying a single integer $n$ - the number of cats.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
CF 1541B - Pleasant Pairs

We are given several test cases, each containing an array of distinct integers indexed from 1. The task is to count how many index pairs $(i, j)$ with $i < j$ satisfy a very specific relationship: the product of the values stored at those positions equals the sum of the…

codeforcescompetitive-programmingbrute-forceimplementationmathnumber-theory
CF 1542B - Plus and Multiply

We start from the number $1$. From any number already in the set, we may perform either of two operations: multiply by $a$, or add $b$. After applying these operations any number of times in any order, we obtain an infinite set of reachable values.

codeforcescompetitive-programmingconstructive-algorithmsmathnumber-theory
CF 1542E2 - Abnormal Permutation Pairs (hard version)

The solution does not answer the stated problem correctly. The expression to be bounded is $$leftlfloor frac{b}{2} rightrfloor le leftlfloor frac{b}{v+1} rightrfloor cdot frac{b}{v+1} le b,$$ but the argument does not correctly establish the lower bound.

codeforcescompetitive-programmingcombinatoricsdpfftmath
CF 1545F - AquaMoon and Potatoes

We are given three integer arrays a, b, c, each of length n. Array a represents a dynamic sequence that can be updated. Arrays b and c are fixed mappings that define relationships: b[x] gives a value associated with x from a, and c[x] gives another value associated with an index.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
CF 1545D - AquaMoon and Wrong Coordinate

Codeforces 1545D: AquaMoon and Wrong Coordinate

codeforcescompetitive-programmingconstructive-algorithmsinteractivemath
CF 1545A - AquaMoon and Strange Sort

We are given a row of friends, each wearing a T-shirt with a number. Initially, all friends are facing right. AquaMoon can swap any two adjacent friends, and whenever she does, both friends flip their facing direction.

codeforcescompetitive-programmingsortings
CF 1547F - Array Stabilization (GCD version)

We are given a circular array of positive integers. In each step, we replace every element with the greatest common divisor of itself and its right neighbor, wrapping around at the end.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdivide-and-conquernumber-theorytwo-pointers