brain
tamnd's digital brain — notes, problems, research
43815 notes
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 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 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 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.
We are given a permutation of the numbers from 1 to n. Each query asks for a recursively defined function over a subarray. Specifically, for a range [l, r], we first find the position of the maximum element in that range.
We are given a string t of length n which is the result of applying an unknown sequence of swaps to an original string s. Each swap exchanges two characters at positions ai and bi in s.
We are counting ways to build a final sequence of unit-sized positions whose total length is exactly $N$. Each position can be either a normal gem or the result of splitting a magic gem.
We are given a set of emotes, each with a positive happiness value. We are allowed to use emotes a fixed number of times, but no single emote can be repeated more than a given number of times consecutively.
We are given a starting point on an infinite grid and a target point. Each day, the environment produces a wind direction from a fixed periodic string. That wind shifts the ship by one unit in one of the four cardinal directions.
Polycarp needs to buy exactly $n$ liters of water using bottles of two fixed sizes: 1-liter bottles at cost $a$ and 2-liter bottles at cost $b$. For each query, we are asked to determine the minimum total cost to acquire exactly $n$ liters.
We are given a tree with $n$ vertices. Each vertex is either colored with one of $k$ colors or left uncolored. The tree is connected, so there are $n-1$ edges. We are asked to select exactly $k-1$ edges and remove them, splitting the tree into $k$ components.
We are tasked with assigning colors to dancers at a ball. There are n pairs, each consisting of a man and a woman, and k available colors.
We are given a tree with n vertices, where each vertex may be colored red, blue, or left uncolored. The task is to count edges that, when removed, separate the tree into two components such that neither component contains both red and blue vertices.
Polycarp must write a coursework of m pages, but he cannot work indefinitely without caffeine. He has n cups of coffee, each with a caffeine dosage ai.
We are given a collection of coffee cups, each with a fixed caffeine value. Polycarp can choose some of these cups and distribute them across several days.
We are asked to arrange n^2 integers into an n x n square matrix so that the matrix is palindromic along both axes. A palindromic matrix does not change when we reverse the order of rows or reverse the order of columns.
We are given an array of weights where each index represents a candy. Tanya will remove exactly one candy and then consume the remaining candies strictly in index order, one per day starting from day 1.
For every triple $(ai,bi,ci)$, we build an array that contains $ai$ exactly $x$ times, $bi$ exactly $y$ times, and $ci$ exactly $z$ times. From each of the $n$ arrays we choose one value. The XOR of all chosen values is some number $t$.
We are given a situation where Evlampy has n identical soldiers and must fight an enemy army composed of m groups, each with a certain health hpi.
We are given a weighted tree. For every degree limit $x$, we may delete any set of edges. Deleting an edge pays its weight. After all deletions, every vertex must have degree at most $x$. For each $x$, we need the minimum total deleted weight.
We are given many sticks whose lengths are powers of two. For each exponent i, there are ai sticks of length 2^i. Each stick can be used at most once, and we want to form as many non-degenerate triangles as possible, where each triangle uses exactly three sticks.
The fridge has height h and exactly two columns. Shelves can be inserted at any heights, which means we are free to divide the fridge into horizontal compartments of arbitrary heights. Each bottle occupies one column and has height a[i].
We are given two matrices, A and B, of size n × m filled with 0s and 1s. We can modify A by repeatedly selecting any submatrix of size at least 2 × 2 and flipping its four corner values.
We are given a street with n houses in a row, numbered from 1 to n, where each house has a color represented by an integer. Ilya wants to pick two houses of different colors and walk between them, measuring the distance simply as the difference in their indices (j - i) for i < j.
I can't responsibly write a complete editorial and solution for Codeforces 1120F from the problem statement alone.
We are given a rooted tree with n vertices, where each vertex has a non-negative price. The root is vertex 1. Leaves are non-root vertices with degree one.
We are asked to determine whether a positive integer $n$ exists for a given integer $a ge 2$ such that multiplying $n$ by $a$ reduces its digit sum by a factor of $a$. Formally, we want $S(an) = S(n)/a$, where $S(x)$ is the sum of digits of $x$.
We are given a string and two costs. The first operation allows us to encode exactly one character for a cost of a.
The town of Shortriver has a single, very long liana of flowers. Each citizen will receive a wreath made of exactly k flowers, cut sequentially from the liana by a machine that always takes the next k flowers in order.
We are given two equal-length decimal strings, representing numbers written digit by digit. The task is to transform the first number into the second one using a very specific operation applied to adjacent digit pairs.
We have a situation that models parallel system testing in a contest setting. There are n solutions submitted to a contest. Each solution i requires a[i] tests to be fully verified.
We are given a collection of distinct positive integers representing candy sizes. Each child must receive exactly two different candies, and the “happiness level” of a child is defined as the sum of the two candies they receive.
We are given a set of students, each belonging to a school, and each with a power rating. The tournament rule is simple: only the strongest student from each school gets selected. Arkady wants to ensure that a chosen set of k students are selected.
We are asked to reconstruct an unknown tree of $n$ vertices by asking a limited type of query. The query is interactive: for any two disjoint, non-empty sets of vertices $S$ and $T$, and a chosen vertex $v$, we receive the number of pairs $(s, t) in S times T$ such that the…
We are asked to count how many ways we can split a given array of integers into contiguous, non-empty segments such that, in each segment, the number of integers that appear exactly once does not exceed a given threshold $k$.
We are asked to construct an array of integers such that a particular greedy algorithm gives a wrong answer by an exact amount.
We are asked to track sequences of English letters encoded in Morse code as we build a string incrementally, one character at a time. The string S starts empty and grows by adding either a dot (0) or a dash (1) at each step.
We have n stations arranged on a directed cycle. From station i, the train always moves to i + 1, and from station n it wraps back to station 1. Every move between neighboring stations costs exactly one second.
We have a circular train network with n stations, numbered from 1 to n. A single train moves from one station to the next in order, looping back to station 1 after station n, taking exactly 1 second per move.