brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given a rectangular board with n rows and m columns. Each row contains exactly one chip. The chips can be located in any column of their respective row.
We are given a grid where some cells are blocked and the remaining cells are usable. Every usable cell must be colored either red or blue. After choosing a coloring, we want to place as many dominoes as possible.
We are given a deck of n cards, each with a color represented by an integer from 1 to 50. The deck is arranged from top to bottom, and we receive q queries.
We are asked to find the smallest positive integer $n$ such that the sum of its divisors equals a given number $c$. Formally, the sum-of-divisors function $d(n)$ sums all numbers that divide $n$ evenly, including $1$ and $n$ itself. For example, $d(6) = 1 + 2 + 3 + 6 = 12$.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are asked to construct a permutation of numbers from 1 to $n$ such that the sum of a contiguous segment from index $l$ to $r$ equals a given value $s$. A permutation here is just an arrangement of all integers from 1 to $n$ with no repetitions.
We are given an array that has been “tampered with” in a very specific way. Originally there was an unknown array of length n, call it a.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given a string composed of characters '0', '1', and '?', along with two integers a and b representing the total number of '0's and '1's that the final string must contain. The task is to replace every '?
We are given a square grid where exactly two cells are already marked with stars. These two stars are the only information we start with, and they define a partial geometric shape on the grid.
We are given two arrays of equal length. You should imagine that each position forms a pair of values, one coming from the first array and one coming from the second. The cost of a configuration is determined by summing the absolute differences of each paired position.
We are given an integer n and a number of operations m. In each operation, every digit d of n is incremented by 1, and if this results in a two-digit number (which only happens for 9), it is replaced by two digits 1 and 0.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are asked to compute the minimum spanning tree (MST) of a weighted graph constructed from an array of positive integers.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are asked to build a permutation of the numbers from 1 to n such that it contains exactly k peaks. A peak is a position strictly inside the array where the value is larger than both immediate neighbors.
We are given an array of integers and multiple queries, each asking about a subarray. For each query, we need to divide the subarray into subsequences, possibly of different lengths, so that no number appears more than half the length of any subsequence, rounded up.
We are given a single apartment floor modeled as a number line, with n rooms located at integer coordinates from 1 to n. Each room has an initial height assigned to it, and we are allowed to modify the heights in a constrained way.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are asked to count arrays of length n where each element lies between 0 and 2^k - 1, such that the bitwise AND of all elements is zero and the sum of elements is as large as possible. The result should be returned modulo 10^9 + 7.
We are given the numbers from $1$ to $n-1$, and we must select as many of them as possible while keeping a very specific multiplicative condition: if we multiply all selected numbers together, the result must leave remainder $1$ when divided by $n$.
We are maintaining a multiset of diamond types where each type has a fixed weight and value per item, but its available count changes over time due to arrivals and sales. On top of this evolving collection, we must answer queries that simulate a greedy packing process.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given a directed graph representing intersections in a city and one-way roads between them, each with a positive integer length. A set of cars starts at specific intersections, each with an odometer that begins at a number s and wraps around to zero after reaching t.
The problem describes a scenario where a country’s road network has been destroyed by an earthquake, leaving n cities and m roads in a disconnected state.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We have a row of n computers, all initially off, and Phoenix wants to turn all of them on. He can manually switch on any computer that is currently off, but with a twist: if a computer has both its neighbors already on, it will turn on automatically without manual intervention.
We are given a set of n blocks, each with a height hi. Phoenix wants to construct exactly m towers using all the blocks. Each tower's height is the sum of its blocks, and a "beautiful" arrangement requires that no two towers differ in height by more than x.
We are given a set of identical right isosceles triangular puzzle pieces. Each triangle has two equal sides and a right angle. Phoenix wants to use exactly $n$ of these triangles to form a perfect square, without overlaps or holes.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We start with the identity permutation of numbers from 1 to n arranged in a row. In one operation, we are allowed to pick any two positions and swap their values. After performing exactly j such swaps, the array becomes some permutation of 1 to n.
We are given an array of up to $10^5$ integers. For each query $[l,r]$, we must split that subarray into the minimum possible number of contiguous pieces such that, inside every piece, the product of all elements equals the least common multiple of those elements.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given an array and allowed to repeatedly compress it by taking two adjacent elements, removing them, and replacing them with their XOR.
We are given an array of non-negative integers, and we can perform a number of “transfer” operations. In one operation, we choose two different elements, subtract one from the first, and add one to the second, provided that the first element does not go below zero.
We are given a sequence of real values $b1, b2, ldots, bn$, which can be interpreted as the altitude of an aircraft at $n$ checkpoints. Each checkpoint restricts the allowed altitude range, so every $bi$ must lie inside a fixed interval.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
Each tent is placed at an integer coordinate and has a positive weight. We may remove any subset of tents. The goal is to maximize the total weight of the tents that remain. The restriction only applies to important tents, meaning tents whose coordinates are both even.
We are given a line of n people, each holding a card labeled either 'C' or 'P'. Each arrangement of cards forms a candidate photo.
We are given a two-dimensional grid representing the explorer space at a conference. Each cell in the grid is a vertex, and each adjacent pair of vertices (up, down, left, right) is connected by an edge with a weight representing the number of exhibits along that edge.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given an $n times n$ lower-triangular part of a chessboard, where only the diagonal and the cells below it matter. On the main diagonal, each cell contains a distinct integer from 1 to $n$, forming a permutation.
We are asked to take a number $n$ and express it as a sum of numbers that are multiples of 2050 scaled by powers of ten. Concretely, the numbers we can use are 2050, 20500, 205000, 2050000, and so on. Each number in this sequence is exactly 2050 multiplied by a power of ten.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given $n$ points in the first quadrant of a plane. Each point is defined by a pair of rational coordinates $(xi, yi)$, where $xi = ai / bi$ and $yi = ci / di$.
We are given two arrays of integers, a and b, both of the same length n. The task is to maximize the sum of element-wise products, $sum ai cdot bi$, by reversing at most one contiguous subarray of a.
Method 1b already provides the key idea. If $(umldots u1u0)3$ is a ternary integer, its decimal value is obtained from the nested form $$(cdots((umcdot3+u{m-1})cdot3+u{m-2})cdots)cdot3+u0.$$ For pencil-and-paper work this means: Start with the leading digit.
We are given a rectangular grid with n rows and m columns. You start at the top-left corner (1, 1) and want to reach the bottom-right corner (n, m) by only moving right or down. Moving right from cell (x, y) costs x burles, moving down costs y burles.
We have two colors of beans, red and blue. Every packet we create must contain at least one bean of each color, and inside any packet the difference between the number of red and blue beans cannot exceed d. The question is whether all
We are asked to find the minimum time for Dima to travel from the top-left corner of a rectangular city grid to the bottom-right corner. The city is represented as an n × m grid where each cell has a value: -1 for blocked, 0 for free, and x 0 for a portal with cost x.
We have a one-dimensional board represented by a string. Each '' is a sheep and each '.' is an empty cell. In one move, a sheep can move exactly one position left or right into an adjacent empty cell.
We are given an array and must count how many index pairs $(i, j)$ with $i < j$ satisfy a very specific relationship between their values and positions.
Each test case gives a sequence of days, where every day is labeled with the task Polycarp worked on that day. The rule is simple: once he stops working on a task and switches to another one, he is never allowed to return to the old task.
We are asked to fill an $n times n$ square grid with the numbers from $1$ to $n^2$ such that no two horizontally or vertically neighboring cells contain consecutive integers. In other words, the difference between numbers in adjacent cells cannot be exactly one.
We start with a tree, meaning a connected graph with $n$ vertices and exactly $n-1$ edges. Each move allows us to remove one existing edge and insert a new edge between any two vertices.
We are given counts of values 1..k. Value i must appear exactly ai times. Empty cells are allowed and are represented by 0. We must place all copies into an n × n matrix and minimize n. Every 2 × 2 submatrix must satisfy two conditions.
We are given an array of positive integers, and we need to transform it into what Nastia calls a good array. A good array is defined as one where every pair of consecutive elements is coprime.
We are asked to reconstruct a hidden permutation of length n containing all integers from 1 to n using an interactive querying mechanism. For each query, we choose two distinct indices i and j, a type t (either 1 or 2), and a threshold x.
A radix conversion routine transforms a nonnegative integer written in one base into its representation in another base. The program under discussion is Method 1a from Section 4.
The empty output indicates a runtime crash before any printing happens, not a logical error in the math. Tracing the execution on the input: The program first reads t = 3, then processes three test cases.
We are asked to help a grasshopper hop across a sequence of tiles represented by an array a. Each tile i contains a number a[i] that defines the maximum distance the grasshopper can jump forward from that tile.
We are given a flat available for n days and m booking requests. Each request is a segment (li, ri) representing consecutive days someone wants to rent. Requests arrive in chronological order.
We are asked to maximize the number of quests William can complete in a 2D grid game with two interacting mechanics: movement and fast travel towers.
We are given an array of even length, representing internal variables of a system. Each variable has an initial positive integer value.
We are asked to compute the expected number of lights that turn on in a line of $n$ lights, given a stopping condition based on consecutive segments of length $k$. Each light starts off, and in each step, one random light that is still off is turned on.
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$.