brain
tamnd's digital brain — notes, problems, research
41650 notes
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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$.
The circle contains numbers $x_1,\dots,x_n$ in cyclic order.
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…
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.
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.
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.
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.
We are given multiple arrays, and for each one we want to select a subsequence that satisfies a very strong internal constraint.
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.
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
The solution is attempting to justify formula (25) via polynomial interpolation of the product polynomial values.
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.
Let $C'$ be the reflection of $C$ across the line $AB$, and let $A'$ be the reflection of $A$ across the line $BC$.
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.
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.
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$.
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.
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.
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.
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.
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.
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.
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.
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.
Let $ABC$ be an isosceles triangle with $AB=AC=s$ and $BC=b$.
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.
Let $ABC$ be an acute triangle.
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.
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.
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.
A partition of $\mathbb{Z}$ into three subsets is encoded by a function $f:\mathbb{Z}\to\mathbb{Z}_3$.
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.
Let the arithmetic progression be
The correction cannot rely on supremum arguments or derived proportionality identities because those depend on unjustified global structure of $f$ and $g$.
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$.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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…
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.
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.
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)$.
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.
Codeforces 1537E2: Erase and Extend (Hard 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.
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.
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.
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.
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.
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.
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.
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$.
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.
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.
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.
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.
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.
The array $b$ is not arbitrary. For every position $i$, $bi$ tells us how many earlier elements of the permutation are larger than $pi$.
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.
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$.
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.
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.
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.
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…
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.
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.
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.
Codeforces 1545D: AquaMoon and Wrong Coordinate
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.
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.