brain
tamnd's digital brain — notes, problems, research
43815 notes
We are asked to determine, for a given string, whether it is possible to split it into three non-empty parts, $a$, $b$, and $c$, such that $a + b + c = s$ and the middle segment $b$ appears as a substring of the concatenation $a + c$.
We are given a set of distinct integer positions on the number line and a starting position. From the starting position, we can move left or right by one unit at a time.
We are given a small array of integers $a = [a1, a2, dots, an]$, with $n le 8$ and a total sum $S = a1 + dots + an le 100$.
We are asked to count valid parking schedules for cars on a tree. Each vertex of the tree will eventually host one car.
We are given a $2 times n$ grid with some cells already filled with integers between $1$ and $k$, while other cells are empty.
We are given several piles of tiles, each containing some zeros stacked on top of ones. For each pile, we know both the initial configuration and the target configuration, where the target also consists of some zeros on top of some ones.
The problem describes a connected, simple undirected graph with n vertices and m edges. A token starts at vertex 1 at time 0. At each integer second t, if the token is at vertex u, you have two choices: either wait one second at u, or move along a specific edge of u.
We are given a set of points on a 2D plane, and the number of points is always even. Our task is to pair all points into disjoint pairs such that the sum of Manhattan distances between the points in each pair is maximized.
We are working on a grid where each cell contains a nonnegative number, and we are only allowed to move either right or down starting from the top-left corner. Any such path from the top-left to the bottom-right has a total score equal to the sum of all visited cells.
We are asked to construct a permutation of integers from $1$ to $n$ such that for every position $i$ from $2$ to $n$, the greatest common divisor of the position and its value, $gcd(pi, i)$, is strictly greater than $1$.
A direct synthetic approach would require tracking the foot of a perpendicular from $B$ to the line $PC$, which suggests that a coordinate representation or vector projection will likely reduce the co…
We are maintaining an array that changes over time, and we are asked to answer two kinds of queries. One type permanently updates a single position in the array.
We are given a binary string. Two players alternate moves, with Alice moving first. The game evolves by repeatedly rewriting parts of the string.
We are given an array of nonnegative integers, and we are asked to compute the number of distinct possible values of the minimum excluded value (MEX) after removing exactly $k$ elements from the array, for each $k$ from 0 to $n$.
We have a tournament with n players. Player i has strength a[i]. Repeatedly, two surviving players are selected, and the weaker one is eliminated. If both strengths are equal, either one may be eliminated. The process stops when exactly k players remain.
The blackboard initially contains every integer from 0 to n - 1. A round always has two moves. First Alice removes some number a. Then Bob must remove a different number b such that $$a+b equiv 3 pmod 4.$$ If Bob cannot find such a number, the game ends immediately and Bob loses.
We are given an array of distinct integers and a set of operations: you can either replace a prefix with its minimum or a suffix with its maximum.
Codeforces 2124I: Lexicographic Partition
We are given an array a. We want to choose a subsequence and reinterpret it as a new array b. The goal is to maximize the length of b, subject to b being a good array. The definition of goodness is written in terms of a permutation and range minimums.
We are building an array of length $n$, but we are not constructing it element by element. Instead, the array is formed by repeatedly appending whole blocks. Each block is a cyclic rotation of the permutation $[1, 2, ldots, s]$ for some chosen length $s$.
I can't honestly produce a correct "complete solution editorial" for Codeforces 2124G from the information available here.
We start with an array and may repeatedly delete elements. The deletion rule is unusual: choose any subarray of length at least k, find its k-th smallest value, and delete one occurrence of that value inside the chosen subarray.
We are asked to count arrays of length $n$ that can be built by repeatedly appending cyclic shifts of the arrays $[1, 2, dots, s]$ for any $s ge 1$, while respecting a set of restrictions of the form $ai ne x$.
We are given an array of positive integers, and our only allowed action is to repeatedly subtract a carefully chosen auxiliary array from it.
We are given an array and may delete any number of elements while preserving the relative order of the remaining ones. After the deletions, the remaining sequence must be non-empty.
We are given an array and we repeatedly look at prefix minimums: at position 1 we take the minimum of the first element, at position 2 we take the minimum over the first two elements, and so on until the full prefix. The final value is the sum of all these prefix minima.
We are given an array b that was generated from an unknown “beautiful” array a, where each element divides the next. Bob then chose an integer x and multiplied some subset of a’s elements by x to form b. Our task is to recover any valid x.
Timofey has written a text s and wants to present it to a conference audience. Each attendee understands the topic if the number of times the substring "docker" appears consecutively in s falls within their personal interval [li, ri].
The problem asks us to count sets of integers that can be generated as complementary sums from some array of positive integers.
We are working with a line of $m$ cells. Each cell must end up being covered by exactly one chosen interval. There are $n$ candidate segments. Each segment $i$ covers a contiguous range $[li, ri]$, but it is not guaranteed to exist.
We are given several strings consisting of uppercase letters. Each letter represents a contest problem. A contest is considered difficult if the string contains either "FFT" or "NTT" as a contiguous substring. We may rearrange the letters of the string in any order.
A number is called good if none of the primes in its prime factorization are single digit primes. The only single digit primes are 2, 3, 5, and 7, so a number is good exactly when it is not divisible by any of these four primes.
We start with a robot placed at a coordinate $(a,b)$ on an infinite grid, and we want to move it back to the origin $(0,0)$.
We are given an array of integers, each between 1 and $n$, and we need to choose a contiguous subarray that maximizes the difference between its median and its minimum element.
We are asked to find, for each array, a contiguous segment whose median minus its minimum is as large as possible. Formally, for a subarray $a[l, r]$, we calculate the median of its elements after sorting, then subtract the smallest element in that segment.
We are given a tree where every vertex has a color and every edge has a weight. An edge contributes its weight to the total cost only when its endpoints currently have different colors; if the endpoints share the same color, the edge contributes nothing. The process is dynamic.
We are given two arrays of integers, p and s, each of length n. Array p represents the prefix GCDs of some unknown array a, and array s represents the suffix GCDs of the same array. The task is to decide whether such an array a exists.
We are given a sequence of casinos, each defined by a range of coins [li, ri] that we must have to play, and a fixed result reali that becomes our new coin count after playing there. We start with k coins and can visit casinos in any order, but only once each.
We are given a sequence of days, each labeled either as rainy (1) or good (0). Jean wants to complete as many hikes as possible. Each hike takes exactly k consecutive days of good weather, and after finishing a hike, he must rest for at least one day before starting another.
The task asks us to find the smallest non-negative integer that shares at least one decimal digit with a given number. For every test case, we are provided a number x, and we need to produce a number y such that some digit in y also appears in x.
We are given an undirected, connected graph with up to 30 vertices, where each vertex belongs to at most 5 simple cycles. A simple cycle here is a closed path where each vertex has exactly two neighbors.
We start with an array of length n, filled with zeros. An operation chooses a positive integer x that is strictly larger than the current minimum value in the array. The operation does not let us choose which position receives the increment.
We are given several independent scenarios. In each scenario there is a collection of bags, each with an initial weight. Time proceeds in discrete seconds. At every second we are forced to remove exactly one remaining bag.
We are given a hidden permutation of integers from 1 to $n$, and we can only access it indirectly through interactive queries. There are four types of queries.
We are asked to recover a hidden permutation of the numbers from 1 to $n$ through a limited set of interactive queries.
We are given a hidden binary string made of opening and closing brackets, and we are allowed to probe it indirectly.
We are given a simple undirected graph whose vertices are labeled from 1 to n. The label itself is also the index of the vertex. The graph does not change, but each query focuses only on a contiguous segment of vertices, from l to r.
We are given a permutation of numbers from 1 to $n$, and a process that colors these numbers one by one in the order of the permutation. Each cell starts white with a score of zero.
We are given a hidden string made only of opening and closing parentheses. We cannot see it directly. Instead, we can query any multiset-like sequence of indices, and the judge constructs a new string by taking the characters at those indices in order.
We are given a hidden bracket sequence of length $n$, consisting only of '(' and ')'. The goal is to reconstruct this sequence by asking at most 550 interactive queries.
We are given a permutation of integers from 1 to n. For each element in this permutation, we are allowed to either leave it as-is or replace it with its “mirror” with respect to 2n, defined as $2n - pi$.
We are given a collection of segments on a line, each segment also acting as an edge between two vertices. From this set we must choose some subset of edges. Two different quantities are computed from the chosen subset.
We are given a multiset of non-negative integers, which we can think of as a bag of numbered tiles. Our goal is to repeatedly choose subsets of tiles and increase a score using one of two rules: either add the sum of the chosen tiles to the score, or add the minimum excluded…
We start with a finite set of distinct positive integers. A single move depends entirely on the current minimum element of the set.
The problem gives us an array of integers, each between 1 and some upper bound $m$, and asks us to find four distinct indices $p, q, r, s$ such that the pair $(ap, aq)$ and the pair $(ar, as)$ are both coprime.
We are given two binary strings, a and b, each of length n. They define a virtual n × n grid where each cell (i, j) contains the value a[i] XOR b[j]. Yuri starts at the top-left cell (1,1) and can only move either right or down.
We are given two arrays, a and b, both of length n. We can perform an operation on a at most once per index: for any index i from 1 to n-1, we can set a[i] to a[i] XOR a[i+1].
We are given a tree, an undirected connected graph with no cycles. Kagari can perform an operation that "re-roots" a path: choose two vertices, remove the edges along the path connecting them, and then reconnect all vertices along that path directly to the starting vertex.
We need to construct an integer array of length n with two properties. The first property says neighboring elements must always have opposite signs. Since their product must be negative, neither element can be zero, and the signs must alternate.
We start with a multiset $S$ of size $n$ and we want to transform it into another multiset $T$ of the same size. The only allowed move takes one element $x$ from $S$, deletes it, and replaces it with either $x+k$ or $ The core question is whether repeated applications of these…
We are given two arrays of equal length, a and b, and a machine called The Lever that iterates a process in which it adjusts the elements of a toward the elements of b.
We are given a rectangular grid of ballerinas, each performing one of 26 possible movements represented by lowercase English letters. Conceptually, each row is a string, and the entire grid is an array of strings.
We are asked to analyze a connected undirected graph representing the Chamomile Valley, where nodes are houses and edges are lanes between them. Rada wants to know which lanes are guaranteed to be part of every shortest path from house 1 to house n.
Each deal lets us buy exactly $3^x$ watermelons for $$3^{x+1} + x cdot 3^{x-1}$$ coins. We need to buy exactly $n$ watermelons. We may use at most $k$ deals. Among all valid ways to do that, we want the minimum total cost.
The problem presents a team of two players, Vadim and Kostya, who each have a collection of cards with numeric values.
We are asked to consider an infinite string formed by writing all positive integers consecutively: 123456789101112... and so on. For each test case, we are given a number k representing the number of digits to take from the start of this infinite string.
We start with a string a. Another string b contains characters that must be inserted one by one, in the order they appear. For every position i in b, the corresponding character c[i] tells us who inserts that character.
We are given a number $n$ that was constructed in a very specific way. Someone secretly chose an integer $x$, then created another number $y$ by appending one or more zeros to the right of $x$. That means $y = x cdot 10^k$ for some $k ge 1$.
The problem gives us a seller who offers watermelons in bundles of sizes that are powers of three. Each bundle of size $3^x$ costs $3^{x+1} + x cdot 3^{x-1}$ coins.
Working
We are working on a tree where an adversary occupies exactly one node, but we never know which one. The adversary is also reactive: after each of our actions, they are allowed to move along one edge or stay in place, except in the special case where we directly queried their…
We are given a line of creepers, each with an explosive power. Detonating a creeper at position $i$ kills all creepers within distance less than its explosive power, specifically positions $j$ such that $ The input consists of multiple test cases, each with $n$ creepers and an…
We are given a network of nether portals represented as a directed acyclic graph. Each portal may have directed connections to other portals, but there are no cycles. The task is to find a longest path in this hidden DAG.
We are given several independent scenarios. In each scenario, there are $n$ villagers, and each villager starts with a non-negative integer value called grumpiness.
We are asked to decide whether a sequence of gears can be arranged in a line such that spinning the leftmost gear at one revolution per second results in the rightmost gear spinning exactly at one revolution per second.
We are given a tree and a very specific local rewiring operation. The operation picks a vertex $b$ with two distinguished neighbors $a$ and $c$. After that, every other neighbor of $b$ is detached from $b$ and reattached to $c$.
We are given a sequence of boxes, each with a hidden power of either 1 or 2. The boxes are placed on a number line at positions 1 through n. We need to discover the power of each box using two interactive queries: swapping adjacent boxes and throwing a ball at a box.
We are given counts for four integers, 0 through 3. Specifically, $c0$ copies of 0, $c1$ copies of 1, $c2$ copies of 2, and $c3$ copies of 3. From this, we can form an array of length $n = c0 + c1 + c2 + c3$.
We are given an array of non-negative integers and we need to make it good by performing the minimum number of operations.
We are given a row of n cells, all initially white. We have two painting operations. The first operation paints a consecutive cells red, starting at any position x such that the red block fits entirely within the row.
We are given an array of positive integers and a positive integer $k$. For each element of the array, we are allowed to either leave it as-is or add $k$ to it in one operation.
We are given a rooted full binary tree where every node represents a function built recursively from its children. Leaves behave simply: their function is just the identity map $fu(x) = x$.
We are asked to count binary strings of a given length that are almost-palindromes under a specific transformation. For a binary string, repeatedly deleting all occurrences of the substring 10 yields a "reduced" string.
The task is to determine the unknown width parameter $W$ of a text editor. The editor displays a sequence of words, each represented by its length, on lines of width $W$.
We are asked to count a specific subset of binary strings of length $n$, which are called almost-palindromes. The key to understanding this problem is the function $f(r)$, which repeatedly deletes all occurrences of the substring 10 from a binary string $r$ until no 10 remains.
We are trying to determine an unknown integer parameter $W$, the width of lines in a text editor. Each article we submit is a sequence of positive integers representing word lengths.
We are given an array of integers, and we want to find the length of the longest subsequence that can be split into "blocks". A block is defined as a contiguous sequence where every element equals the length of that sequence.
We are given a connected undirected graph where each vertex may have a weight, but some weights are missing and represented by -1. The goal is to fill in the missing weights such that the graph becomes balanced.
The original problem is interactive. We know a set of anchor points, and there is a hidden robot position. By moving the robot and observing the minimum Manhattan distance to any anchor, we must recover the initial coordinates.
We know the score at halftime and the score at full time. If the halftime score is a:b, then during the first half the RiOI team scored exactly a goals and the KDOI team scored exactly b goals.
We are given a directed acyclic graph with n nodes and m edges. Each node starts colored blue, and players Cry and River play a two-player token game. The token starts at a node s. Cry moves first, then River, and they alternate.
We are given a sequence of numbers, and we want to interpret each number in that sequence as a frequency requirement for some unknown array we must construct.
For any array $x$, its sequence of prefix maxima is completely determined. At position $i$, the prefix maximum is $$max(x1,x2,dots,xi).$$ We are allowed to build another array $z$ whose prefix maxima are identical to those of $x$.
We are given an array of integers and asked to perform a special transformation multiple times. For each element in the array, we replace it with the minimum non-negative integer that does not appear anywhere else in the array.
We are given the result of running the Collatz operation exactly k times and the final value x. The task is not to find the original value uniquely, because many different starting values may lead to the same result.
We are given two integers, $a$ and $b$, and we can pick a positive integer $k$ such that $b$ is divisible by $k$. Then we replace $a$ with $a cdot k$ and $b$ with $b / k$. The goal is to make the sum $a + b$ as large as possible while ensuring it is even.
We are given a permutation $p$ of size $n$, meaning it contains each integer from $1$ to $n$ exactly once. We must construct another permutation $q$ of the same size, also a rearrangement of $1$ to $n$, with a structural constraint linking adjacent positions.
We start with two fixed points in the plane, one at the origin and one at $(1,0)$, connected by a segment. The only allowed way to create new points is by repeatedly selecting an existing segment, treating its endpoints as two vertices of a triangle, and then placing a third…
We are asked to construct a square matrix with small integer entries, limited non-zero elements per row and column, and a determinant equal to a given target number.
The determinant can be written using the Leibniz formula: $$det(M)=sum{sigma} operatorname{sgn}(sigma)prodi M{i,sigma(i)}.$$ A brute force viewpoint is to think of each permutation as choosing one outgoing edge from every row and one incoming edge into every column.