brain
tamnd's digital brain — notes, problems, research
41650 notes
We are asked to rearrange students in a classroom so that no two students who were neighbors in the original seating remain neighbors in the new arrangement. The classroom is an n×m grid, and the students are numbered sequentially from 1 to n·m in row-major order.
Valentin is playing a game where a single unknown letter has been chosen, and every time he pronounces a word containing that letter, he gets shocked. He can also make guesses about the letter, and incorrect guesses result in shocks.
The graph consists of two directed chains. Vertices $A1,dots,An$ form one chain and $B1,dots,Bn$ form another. Capacities on the $B$-chain are fixed. Capacities on the $A$-chain are updated online.
We are given a 4-row by n-column matrix filled with either asterisks or dots. The asterisks represent tiles that must be cleared. The allowed operation is selecting a square submatrix of size 1×1 up to 4×4 and replacing every asterisk inside it with dots.
Vova is fighting a monster called the Modcrab. He has a set amount of health, an attack value, and an unlimited supply of healing potions. Each potion restores a fixed number of health points, and crucially, the potion heals more than the Modcrab can deal in a single attack.
We are given an array of up to 200000 integers. For every pair of positions $(i,j)$ with $ile j$, we evaluate a special function $d(ai,aj)$, and we need the sum over all pairs. The function behaves differently from a normal difference.
We are given $k$ strings of the same length $n$. Each of them was produced from a single unknown original string by performing exactly one swap of two different positions. The swapped characters are allowed to be equal, so a string may remain unchanged after the operation.
We are given n cubic boxes, each with a side length specified by an array a. Mishka wants to nest these boxes inside each other according to strict rules: a box can go into another box only if it is strictly smaller and the larger box does not already contain another box.
The task asks whether Ivan can buy exactly x chicken chunks using only small portions of 3 chunks and large portions of 7 chunks.
We are given a rooted tree with n vertices, where vertex 1 is the root. Each vertex must be colored with a target color specified in the input. Initially, all vertices are color 0.
We are given an unknown directed graph with n nodes. For each pair of nodes u and v, we are told a Boolean condition that involves reachability in the graph: either the AND, OR, or XOR of whether u can reach v and whether v can reach u is true.
We see one side of every card. A visible side can be either a lowercase letter or a digit. The statement we want to verify is: "Whenever a card has a vowel on one side, the other side contains an even digit." We may flip some cards.
We are given a sequence of program statements. Each statement is either: f , a for statement whose body must contain at least one statement at one indentation level deeper. s , a simple statement that occupies exactly one line and does not create a new block.
We are given several strings made from the letters 'a' through 'j'. Originally, these strings were decimal numbers. A prankster replaced every digit with a unique letter, creating a one-to-one correspondence between the ten digits 0...9 and the ten letters a...j.
We are given an array of integers. Among all values in the array, there is a smallest value, and the problem guarantees that this minimum value appears at least twice. Our task is to find the smallest distance between any two occurrences of that minimum value.
We are given a rooted tree with vertices numbered from 1 to n. Vertex 1 is always the root. For every other vertex, the input tells us its parent, which completely defines the tree structure. A vertex is considered a leaf if it has no children and is not the root.
We are given a mutable string and a sequence of queries. Each query either changes a character at a specific position or asks how many times a smaller string appears as a substring within a specific substring of the main string.
We have a game where Conan and Agasa take turns removing cards from a pile. Each card has a positive integer written on it. When a player chooses a card, not only does that card get removed, but all cards with strictly smaller numbers are removed as well.
We are given two integers, a and b. Our task is to rearrange the digits of a to produce the largest possible number that does not exceed b. The resulting number must use all digits of a exactly once and cannot have leading zeros.
We want to represent a positive integer n as a sum of exactly k powers of two: $$n = 2^{a1} + 2^{a2} + cdots + 2^{ak}$$ The exponents may be positive, zero, or even negative. Among all valid sequences of length k, we first minimize the largest exponent that appears.
We are given a string consisting of three possible characters: '(', ')', and '?'. For every substring, we ask whether it can be turned into a non-empty correct bracket sequence by replacing each '?' independently with either '(' or ')'. Such a substring is called pretty.
We are asked to generate a string of length n consisting only of the letter 'O' in uppercase and lowercase, following a rule based on the Fibonacci sequence. The positions in the string that correspond to Fibonacci numbers (1, 2, 3, 5, 8, ...
A positive integer is called perfect when the sum of all of its decimal digits is exactly 10. We are given an integer k, and we must output the k-th smallest positive integer whose digit sum equals 10. The ordering is the usual numerical ordering.
We are given a linear garden with n consecutive beds and a subset of these beds containing water taps. Each tap, once turned on, waters the bed it occupies immediately, and in each subsequent second it extends its coverage by one bed in both directions.
We are given an integer $n$, and we want to represent a fixed rational number, specifically $1 - frac{1}{n}$, as a sum of several smaller fractions. Each fraction must have a denominator that is a proper divisor of $n$, meaning it divides $n$ but is neither 1 nor $n$.
We are given two sets of vertices, each with n nodes, and m edges that connect vertices from the first set to vertices in the second. Each edge has an associated cost.
We are given a long one-dimensional route made of consecutive segments. Each segment has a length and a terrain type, either grass, water, or lava. Bob starts just before the first segment and wants to reach the far end after the last segment.
We are given a set of obelisks on a 2D plane and a set of clues that indicate vectors from obelisks to a hidden treasure. Each obelisk has exactly one clue, but the mapping is scrambled, so we do not know which clue belongs to which obelisk.
We are given n vertices, each with a number ai written on it, and no edges initially. We can connect any two vertices by paying the sum of their numbers ax + ay. Additionally, there are m special offers, each allowing a particular edge to be added at a discounted cost w.
We are given a list of numbers representing an array, and we are allowed to remove exactly one element. After removing it, we look at how “spread out” the remaining numbers are, defined as the difference between the largest and smallest remaining value.
We are asked to simulate operations on a set of multisets, each initially empty. The operations are either assigning a single value to a multiset, combining two multisets via union, combining two multisets via a multiset product using greatest common divisors, or querying the…
The game Gennady plays involves matching cards either by rank or suit. In practical terms, you are given a single card on the table and a hand of five cards.
We are asked to think about building a figure composed of unit squares drawn on a grid, where every square is outlined by horizontal and vertical unit segments. Each segment can be either horizontal or vertical, and every segment has length exactly one.
We are building a very specific circle configuration. There is one central circle of radius $r$. Around it, $n$ identical circles are placed so that they form a ring.
We have a sequence of cities arranged along a single road at increasing distances from the origin. Each truck travels from a starting city to a destination city along this road. The trucks consume fuel linearly with distance and start with a full tank.
We are given a string containing letters and a few special characters: [, ], :, and The constraints tell us that the string can be up to 500,000 characters long.
We have a rectangular grid of numbers with $n$ rows and $m$ columns. We are allowed to reorder the rows however we like, but the order of numbers within each row is fixed.
We are given the sequence of integers from 1 to $n$. The task is to divide this sequence into two disjoint sets $A$ and $B$ so that the absolute difference between their sums, $ Since $n$ can be as large as $2 cdot 10^9$, explicitly constructing the sequence or trying all…
We are asked to count how many arrays of length $n$ can be formed such that every element lies within a fixed interval $[l, r]$, and the total sum of all elements is divisible by 3.
We are given an even-length list of positive integers, and we must partition these numbers into groups. Each group must contain at least two elements, and every number must belong to exactly one group.
We are given a fixed sequence of hits, where each hit has a damage value and is associated with a specific button (a lowercase letter). We are allowed to delete any hits from the sequence while keeping the remaining ones in their original order.
Vasya starts with zero burles and wants to buy a car. The bank offers n credit deals, each giving him an initial sum ai immediately and requiring monthly payments of bi for ki months. Vasya can take at most one credit per month, but multiple credits can overlap.
Vasya wants to assemble a contest from a sequence of problems, each with a difficulty and a cost. He gains a fixed reward for including any problem, but he also pays two types of costs: the direct payment to each problem’s author and a “gap penalty” based on the largest…
We are given a binary string that we are allowed to repeatedly compress until nothing remains. A single move consists of picking a contiguous block of identical characters, either all 0s or all 1s, removing that block from the string, and concatenating the remaining parts.
We are given a square matrix of size $n times n$, but instead of being explicitly written as bits, each row is packed into hexadecimal characters. Each hex digit represents four binary cells, so the input is just a compact encoding of a binary matrix.
We are given a string of digits, each between 1 and 9. The task is to split this string into at least two consecutive segments so that when we interpret each segment as an integer, the resulting sequence is strictly increasing.
We are asked to answer multiple independent queries. Each query gives two numbers, a position $k$ and a digit $x$ between 1 and 9. For each query, we need to output the $k$-th positive integer whose digital root equals $x$.
We are given a line of lamps, each painted in one of three colors: R, G, or B. We are allowed to repaint any lamp to any other color.
We are given a connected undirected graph with n vertices and m edges, each with a positive weight. The goal is to adjust some edge weights by incrementing them, so that the graph's minimum spanning tree (MST) remains the same cost as initially but becomes unique.
We are given an array of integers and a collection of segments, each defined by a start and end index. Each segment can be applied at most once to decrease all values in that segment by one.
We are given an integer array and a collection of intervals over its indices. Each interval represents an operation: if we select it, every position inside that range is decreased by exactly one.
We are given a linear sequence of lamps, each painted either red, green, or blue. The task is to change as few of them as possible so that no two consecutive lamps have the same color.
We are given two line segments on the number line, each defined by its endpoints. For each query, we need to pick one integer point from the first segment and one integer point from the second segment such that the points are different.
We are given a shuffled list of integers, each representing a divisor of one of two unknown positive integers, which we can call x and y. If a number divides both x and y, it appears twice in the list. Our task is to reconstruct any pair (x, y) that could have produced this list.
The problem models a “patience bowl” which has an initial amount of patience that can grow or shrink over time depending on the tap’s speed. The tap’s speed can be changed at discrete times by events.
We are given an $n times m$ grid where every cell contains a unique value from $1$ to $nm$. These values impose a global order on the cells, and we should think of the grid as being revealed gradually: first the cell with value 1 appears, then 2, and so on.
We are asked to count how many different weighted trees can be built on $n$ labeled vertices when every edge weight is an integer between $1$ and $m$, under a single global constraint involving two distinguished vertices $a$ and $b$.
We are maintaining an array of integers that is repeatedly modified and queried. The array starts fixed, but over time we apply operations that either scale a contiguous segment, shrink a single element by dividing it, or ask for the sum over a segment.
We are given a string that is already a palindrome, and our goal is to transform it into a different palindrome by cutting it into some number of contiguous pieces and then reordering these pieces. The task is to find the minimum number of cuts required to achieve this.
We are asked to find "funny pairs" in an array of integers. A pair of indices $(l, r)$ is funny if the subarray from $l$ to $r$ has even length and the XOR of the first half equals the XOR of the second half.
We are asked to construct a digit string of fixed length n. Every substring of this string is interpreted as a number (ignoring leading zeros), and we get a score of 1 for a substring if that number lies in the inclusive interval [l, r].
The problem gives a number $n$ not in decimal form, but in some arbitrary base $b$. The digits of $n$ are listed from the most significant to the least significant, and the task is to decide whether $n$ is even or odd in decimal.
We are asked to analyze a game of tic-tac-toe played on a tree. Each vertex is either uncolored or already white. Two players alternate coloring vertices, starting with white. The first player to complete a path of three vertices in their color wins.
We are given a rooted tree where the parent of each node is fixed by input order: node i connects to some earlier node pi, forming a rooted structure at node 1.
We are given a multiset of tiles, where each tile carries an integer value between 1 and m. The goal is to repeatedly pick disjoint groups of exactly three tiles and form as many such groups as possible.
We are given an array of integers representing charges on a line of stones. A single operation picks any interior position and replaces its value using its two neighbors: the new value becomes the sum of the left and right neighbors minus its old value.
We are given a sorted list of positions on a long line segment where damage has occurred. Each damaged position must be covered by tape, but the tape does not need to avoid healthy positions, it can freely cover anything in between.
We are given a number $a$. For this number we are allowed to pick any $b$ such that $1 le b < a$. For each choice of $b$, we compute two values derived from bitwise operations: one is $a oplus b$, the other is $a & b$. We then take the gcd of these two results.
We are given two lowercase strings representing superhero names. A transformation is allowed if every vowel can be changed into any other vowel, and every consonant can be changed into any other consonant. The actual letters do not matter.
We are given a row of holes, each containing exactly one villain, and each villain has a type represented by a character. The string representing the colony is of even length, so it can naturally be divided into two halves.
We are given a tree with n nodes and multiple queries. Each query provides a subset of k nodes, a maximum number of groups m, and a root r.
We are given a group of superheroes, each with an initial power value. We are allowed to modify this group using two types of operations: we can either remove a superhero from the group (as long as at least two remain), or we can increase the power of a chosen superhero by one.
We are given a linear base of length $2^n$, where some positions contain avengers. Thanos wants to destroy the entire base using minimum power.
We are given an array of integers representing the power of n magnetic machines. Each machine contributes positively to the total power of the farm.
Sasha wants to drive from city 1 to city n along a straight line of cities. Each city is exactly one kilometer apart, and all roads go forward, so he cannot move backward. His car consumes one liter of fuel per kilometer and starts with an empty tank.
We have three people with different grape preferences and three piles of grapes. Andrew wants exactly the first type of grape, green grapes. If he needs x grapes, all of them must come from the green pile. Dmitry dislikes black grapes. He can eat green or purple grapes.
We have an array of integers, each between 1 and 300, and we need to process two types of queries. The first query multiplies a contiguous segment of the array by a given number.
We are given a hidden array of size $n$, but the array is not directly accessible and is permuted arbitrarily. The only structural guarantee is that if we sort its elements, they form a perfect arithmetic progression with a strictly positive common difference.
We are given a row of n colored squares, each labeled with an integer representing its color. The goal is to recolor the entire row into a single color using a series of "flood fill" operations.
We are given a sequence of integers a of length n, and two parameters: m, the number of largest elements we consider when computing the "beauty" of a subarray, and k, the number of contiguous subarrays we must partition a into.
We are asked to compute the number of trailing zeros in the factorial of a number when represented in an arbitrary base. More precisely, given integers $n$ and $b$, we want the number of digits equal to zero at the end of the base-$b$ representation of $n!$.
We are asked to implement a quantum operation on an array of qubits. The operation must correspond to a unitary matrix whose only non-zero entries lie on the anti-diagonal. For a system of $N$ qubits, the state space has dimension $2^N$.
We are asked to implement a quantum unitary operation on $N$ qubits, where $N$ is small, between 2 and 5. The operation is represented by a $2^N times 2^N$ matrix with a specific block structure. The matrix can be visualized as four quarters: 1.
We are asked to implement a unitary operation on $N$ qubits, where $2 le N le 5$. The operation is represented by a $2^N times 2^N$ matrix with a chessboard-like pattern of zeros and non-zero elements.
We are given a small quantum register of at most eight qubits that encode an input bitstring $x0, x1, dots, x{N-1}$, along with one extra qubit $y$ that acts as an output wire.
We are asked to implement a quantum oracle acting on a small register of qubits. The oracle receives an input string encoded in quantum form, represented by an array of up to eight qubits, plus one additional qubit that serves as the output bit.
We are asked to implement a quantum operation that computes the logical AND of an array of qubits. Concretely, we have a set of $N$ qubits, each representing a binary value (0 or 1, though they can be in superposition), and a single output qubit.
We are asked to implement a quantum operation on a small number of qubits (2 to 4) such that the unitary matrix representing it has an upper Hessenberg form.
We are given a very specific 8×8 pattern describing where a 3-qubit unitary matrix has non-negligible entries. The matrix is not arbitrary, it is extremely sparse and structured, and the task is to implement any quantum circuit on 3 qubits whose unitary matches this sparsity…
We are asked to implement a quantum operation on an array of $N$ qubits, where $N$ ranges from 2 to 5. The core requirement is that the operation's unitary matrix has a very particular pattern: a central 2x2 submatrix filled with non-zero values, anti-diagonals in the top-left…
We are asked to implement a unitary operation on a quantum register consisting of $N$ qubits, where $2 le N le 5$. The unitary is represented as a $2^N times 2^N$ matrix, and it must have non-zero entries only on the main diagonal and the anti-diagonal.
We are asked to construct a quantum operation on $N$ qubits whose matrix, in the computational basis, has a very rigid block structure. The full unitary is a $2^N times 2^N$ matrix, and we are not required to compute or print it explicitly.
We are asked to implement a unitary operation on an array of $N$ qubits, where $2 le N le 5$, such that the matrix representing the operation has a very specific block-diagonal structure.
We are given a small register of qubits that encode a bitstring and an additional single qubit that acts as an output accumulator.
We are asked to implement a quantum oracle that checks whether a given bit string is periodic. In practical terms, imagine we have an array of $N$ qubits, each representing a bit, and a separate output qubit.
We are asked to work with a single qubit that is guaranteed to be in one of three specific quantum states: $ Our goal is not to identify which state the qubit is in, but to return a number corresponding to a state we are sure the qubit is not in.
We are asked to implement a "quantum oracle" that checks whether a binary vector alternates. That means for an input array of bits x[0..N-1], we need to determine if no two consecutive bits are the same.
We are given three qubits in one of two specific entangled states, each a superposition of three computational basis states with complex coefficients derived from the cube roots of unity. The two states differ only in the phase factors applied to the second and third qubits.
We are given an array of integers and may choose any contiguous subarray. For every chosen subarray, we can compute its arithmetic mean, which is the sum of its elements divided by its length. The task is to find the maximum possible mean among all subarrays.
We are given a string consisting of the first p letters of the lowercase English alphabet, and a symmetric adjacency matrix A that specifies which letters can appear next to each other. A string is crisp if every consecutive pair of letters in it is allowed by this matrix.