brain
tamnd's digital brain — notes, problems, research
41650 notes
We are given four separate bags, each containing some number of candies. Each bag is indivisible and must be given entirely to exactly one of two friends.
We are given a rectangular grid of integers. Some cells already contain fixed positive values, while some cells contain zeros that we are allowed to replace with positive integers of our choice.
We are given two strings of equal length. The only operation allowed is to pick a character from the current string and move it either to the very front or the very back. Every move removes that character from its position and reinserts it at one of the two extremes.
We are given a set of teams and a list of potential matches between pairs of teams. Each match can either be played in one of several stadiums or be skipped entirely.
We are given a string of lowercase letters, where each position acts like a “tile” labeled by a character. A cursor sits on one of these positions, and we are allowed to move it using a special jump operation: pick a character and a direction, and the cursor teleports to…
We are given two very large sets of integers, but they are not listed explicitly. Instead, each set is described as a union of intervals.
We are given an array of mountain heights. A “peak” is an index strictly inside a segment where the height is larger than both immediate neighbors, meaning it forms a local maximum. We are also given a fixed window length $k$, and we slide this window across the array.
We are given several independent scenarios about a bag of rice grains. In each scenario, there are two layers of uncertainty: the weight of each individual grain and the total weight of all grains together.
We are given a simple undirected graph where people are vertices and friendships are edges. A valid party is a selection of exactly five distinct vertices such that the induced subgraph on these five vertices is either completely empty of edges or completely full, meaning it…
The grid describes a rectangular factory floor where each cell is a tile that may have walls on some of its four sides. Each tile contains a number from 0 to 15, and this number encodes its walls using four bits.
We are given an array of numbers laid out in a line. Two players alternate turns, starting with Alice. On each move, a player removes either the leftmost or rightmost remaining element and appends it to a sequence that is being constructed.
We are given a list of positive integers, and we are allowed to permute them in any order before processing. After choosing an order, we build prefix GCDs: the first value is just the first element, the second is the gcd of the first two elements, and so on until the full array.
We are given a sequence of numbers arranged in a line. In one move, we are allowed to take one unit from some position and push it to the next position on the right. This means mass can only flow to the right, never backwards, and every move preserves the total sum of the array.
We are given a line of positions from 1 to m. At each position i there is a value pi, and we may choose to activate some subset of these positions. We are also given n intervals on the same line. For each interval [l, r], we look at the activated positions inside it.
We are given a permutation of size $n$, and we repeatedly apply a very specific “bullying” operation to measure how far the permutation is from being sorted. At any moment, we look at all indices where the value is not already correct.
Each test case gives a tree, and we must assign every vertex a label of either 0 or 1. Once the labels are fixed, every pair of vertices defines a unique simple path in the tree, and we look at the sequence of labels along that path.
We are given two arrays of equal length, and we need to count how many index pairs behave in a very specific “cross condition”.
We are given a tree described by an ordered list of edges. The edges are not just connectivity information, their order matters because the drawing process scans them sequentially again and again. The process starts with only vertex 1 being considered “drawn”.
Working
We are given a single string and we are asked to count how many ordered pairs of non-empty substrings $(a, b)$ satisfy a very rigid structural property: every occurrence of $a$ inside the string must always be followed by the same fixed middle string $c$ and then $b$, and…
We are given an undirected simple graph and asked whether we can select a subset of its edges that forms a very specific structure called a Fish Graph. The target structure consists of two parts. First, there must be a simple cycle.
We are working with an array where we need to answer many independent range queries. Each query gives a segment of the array, and for that segment we want the maximum possible length of a subsequence that avoids a very specific forbidden pattern: three chosen elements that…
We start with a multiset of real values, initially all integers. One operation takes any two values, removes them, and replaces them with their average. This operation reduces the size of the multiset by one, and repeats until exactly two numbers remain.
We are counting sequences of length n, where each position holds a digit in base k. So each ticket is just an array of length n with values from 0 to k-1.
We are counting digit sequences of fixed length in base $k$. Each ticket is just an array of $n$ numbers, each between $0$ and $k-1$. A ticket is considered valid if we can pick one position $i$ such that the digit at $i$ is equal to the sum of all other digits, taken modulo $k$.
We are given multiple independent queries. Each query describes a contiguous range of integers from $l$ to $r$, and each integer in that range represents a starship identifier.
We are given multiple queries. Each query describes a range of integers from $l$ to $r$, and each integer represents a candidate “starship number”.
We are given a circular dial with $k$ positions. Each position is labeled with a distinct letter from the first $k$ letters of the alphabet. We are allowed to permute which letter sits at which position before starting.
We are given a connected, undirected graph with unit-length edges. The key quantity of interest is the graph diameter, which is the largest shortest-path distance between any pair of vertices.
We are given an undirected, connected graph with up to 20 vertices. Each vertex represents a server, and edges represent direct bidirectional communication links. For every server $u$, we must choose exactly one adjacent vertex $a(u)$.
We are given a sequence of integers and a fixed length $k$. The task is to modify the sequence as little as possible so that it no longer contains any contiguous block of length exactly $k$ that is monotone.
Each edge in a connected undirected graph carries a value that starts at zero. We are allowed to perform operations, and each operation picks a spanning tree of the graph and adds a single chosen value $v$ to every edge in that tree.
We are given aggregated statistics for a football team over a sequence of matches. Instead of knowing individual match results, we only know three numbers: how many matches were played, how many total goals the team scored across all matches, and how many total goals it conceded.
We are interacting with a hidden integer $n$, but we are not allowed to see it directly. Instead, we can ask up to 10 questions of the form: “what is the $k$-th digit from the right of $n!$ in decimal representation?”.
We are playing a coordinate guessing game on a large integer grid. There is a hidden target point somewhere in the square from $(0,0)$ to $(10^6,10^6)$.
We are given a rooted binary tree with $n$ employees. Each employee has either zero or two direct subordinates, and there is a unique root (the CEO).
We are given a permutation $a$ of size $n$, meaning every number from $1$ to $n$ appears exactly once. We are allowed to apply two permutations $q$ first and then $p$, so that the final position $i$ receives the value originally at position $p[q[i]]$.
We are given several vertical stacks of uniquely numbered blocks. Each stack is ordered from top to bottom, and we are allowed to physically reorganize these blocks using two operations: we can cut a stack into two by taking a prefix or suffix segment and turning it into a new…
We are given a circular arrangement of $n$ positions, each holding a value modulo $m$. The goal is to transform every value into zero.
We are given an (n times m) grid where each cell behaves like a directional device that routes a “laser” entering from one side to another side, while possibly increasing its speed.
I can’t produce a correct editorial for “Codeforces 1740H - MEX Tree Manipulation” from the title alone. That problem number corresponds to a very specific and fairly technical tree + data structure task, and without the exact statement (operations, constraints, and what…
We start with a collection of $n$ single-element sets, one for each value in the array. Each position contributes a separate set, even if values repeat. The only operation allowed is merging two currently existing sets, but only if they are disjoint as sets of values.
We are given a rooted tree where each node represents a card. Card 1 is fixed as the root, and every other card hangs from exactly one earlier card, forming a structure where every node has a single parent and edges always point toward smaller indices.
We are given a grid, but only two cells actually behave like “real endpoints”: the top-left cell acts as a source holding a stack of cards, and the bottom-right cell acts as a sink where we must rebuild a stack in sorted order from 1 to k, increasing from top to bottom.
We are given several test cases, and each test case starts with a prime number $n$. For every such $n$, we must choose another prime number $m$ such that the sum $n + m$ is not prime.
We are given a multiset of integer weights representing bricks, and we must distribute every brick into one of three non-empty groups.
We are given several test cases. In each test case, we receive a collection of rectangles, each representing a cheese slice. Each slice can be rotated, so a rectangle $a times b$ can be treated as either width $a$, height $b$ or width $b$, height $a$.
The construction defines an infinite binary string where each stage doubles the previous string and flips the bits in the second half.
We are asked to construct an $n times n$ matrix over the field of residues modulo a prime $n$. Every entry must be an integer in the range $0$ to $n-1$, and the diagonal is already fixed: the $i$-th diagonal entry must equal $bi$.
We start at position k on a line of n slimes. Each position contains a slime with some health value, and when we step onto a position that still has a slime, we absorb it and add its health to ours. Negative values reduce our health, positive values increase it.
The structure is a triangular grid where row i contains i cells, and each cell can send influence downward to two children: directly below-left and below-right.
The system describes a 120 by 120 grid where every cell initially contains a conveyor belt pointing to the right. A single slime starts at the top-left cell, and every second the system evolves in a synchronized way.
We are given two binary strings of equal length. We are allowed to repeatedly apply an operation that flips two positions at once: pick indices l and r with l < r, and invert both bits. The cost depends only on whether the chosen positions are adjacent or not.
We are given two binary strings of equal length. We are allowed to fix mismatches between them by flipping pairs of positions in the first string. Each operation picks two different indices and toggles both bits at those positions.
We are given an array of integers, and we are allowed to rearrange elements using a restricted swap operation. The restriction is that we can only swap positions whose indices share the same remainder when divided by a fixed number $k$.
We are given a very specific elimination-style tournament. Players arrive in a fixed order from 1 to n. The first match is between player 1 and player 2, then the winner of that match plays player 3, then that winner plays player 4, and so on until player n.
We are given an array of integers and a peculiar operation that allows us to “transfer” values between two positions, but the direction of the transfer depends entirely on the parity relationship between the chosen pair. Each operation picks two indices l < r.
Each position in the array behaves like a pair of values, a dynamic value $ai$ and a fixed value $bi$. Over time, we repeatedly overwrite entire segments of the $a$-array with a single number, and occasionally we are asked to inspect a segment and find the smallest value of a…
We maintain a dynamic set of non-negative integers. It starts with a single element, zero, and evolves through three types of operations: insert a new number, delete an existing number, and answer a query that depends on a parameter $k$.
We start with a set that initially contains only the number zero. Over time, two kinds of operations are applied. One operation inserts a new integer into the set, and the other asks a query about a special value called the k-mex.
We are given a binary string, and we want to transform it into a non-decreasing sequence, meaning that once the string starts containing 1, it should never go back to 0. The final form must look like some number of 0s followed by some number of 1s.
We are given an array and multiple range queries. For each query interval, we must choose a contiguous subarray fully inside that interval and maximize a score defined on that subarray.
We are given an array and we are allowed to choose any contiguous segment inside it. For each segment, we compute a score defined as the difference between its sum and its bitwise XOR.
We are working on an $n times n$ grid where each cell $(i, j)$ contains a value equal to the product $i cdot j$. A character starts at the top-left corner $(1, 1)$ and must reach the bottom-right corner $(n, n)$, moving only right or down at each step.
We start with a graph of $n$ labeled vertices and no edges. The goal is to end with exactly $m$ undirected edges. Each edge between vertices $u$ and $v$ is not freely chosen: its weight is fixed and equals $gcd(u, v)$.
We are given several independent grids, each grid representing a city map where every cell contains a building height. From each grid, we must choose a square subgrid of size $l times l$ such that every cell inside that square has height at least $l$.
We are given an array of integers, and we look at every contiguous segment of it. For each segment we compute the bitwise XOR of its elements, producing a single number.
We are given a permutation p of size n, and we must construct another permutation q of indices 1..n. The constraint on q is unusual: if we look at the values of p along q, they cannot drop by more than k as we move forward.
The task is to count how many contiguous subarrays of a given array have a very specific structural property: if you look inside the subarray, take its smallest element and its largest element, the larger one must be an exact multiple of the smaller one.
We are given two strings of equal length. Think of them as two rows of characters, each row having $n$ positions.
We are given a line with people standing at different coordinates. Each person has a fixed position and also a personal preparation time before they can start moving.
We are given several independent test cases. In each test case there is a multiset of integers, where each integer represents an orbit label of a planet. Planets sharing the same value belong to the same orbit. We have two ways to destroy planets.
We are interacting with a hidden structure that is guaranteed to be a simple cycle on $n$ vertices, where $n$ can be as large as $10^{18}$. The vertices are labeled by distinct integers, but the actual cycle order is unknown.
We are given a text string and a pattern string. The operation allowed is to pick any occurrence of the pattern inside the text and replace that entire occurrence with dots. Those dots still occupy positions but no longer participate in further pattern matches.
We are given a collection of friends where each friend has two numbers: how much they intend to spend at a restaurant and how much money they actually have. The goal is to partition some of these friends into disjoint groups, where each group has at least two people.
We are given a string of lowercase letters representing a line of tiles. Each position is a node in a path from the first character to the last, but we are not required to move only to adjacent positions.
We are given a string that was produced by encoding a lowercase English string character by character. Each letter was replaced by its position in the alphabet, with the extra twist that two-digit positions are marked by appending an extra 0 after the number.
The situation describes a decision between two elevators that can potentially reach Vlad on the 1st floor. Each elevator has a different movement rule, and the goal is to determine which one arrives back to floor 1 the fastest after Vlad presses a call button.
We are working on a one-dimensional segment from 0 to d. Some positions on this line are special points that must be “covered”. We also have a collection of lantern positions, and each lantern can be assigned a nonnegative power up to d.
Each dish must receive exactly one seasoning choice: either red pepper or black pepper. If a dish uses red pepper, it contributes $ai$ to the total tastiness, otherwise it contributes $bi$. So the final score is fully determined once we decide a binary assignment for all dishes.
We are given two arrays of equal length. Each position contains a positive integer, and we are allowed to repeatedly replace a number by the number of digits it has in base 10.
We are given several test cases. In each test case, there are several colors of balls, and each color has a certain number of balls. The total number of balls across all colors is guaranteed to be odd.
We are playing a two-player game on a string that behaves like a deque. The string initially contains lowercase letters and has even length. Alice moves first, and players alternate.
We are given a convex polygon described by its vertices in counter-clockwise order. The shape is not arbitrary: every corner is either a right angle or slightly wider than a right angle, but never sharp.
We are given a group of $n$ people, each starting with a happiness value $ai$ and a binary personality flag $bi$. We choose a permutation, which represents the order in which they speak.
We are asked to count how many permutations of size $n$ satisfy a very specific structural constraint involving both the permutation and its inverse.
We are given a connected undirected graph with a small number of extra edges beyond a tree. For each edge, we must decide whether it is colored red or blue.
We are given a balanced bracket string of length $2n$. Each position in this string is treated as a vertex in a graph. Two vertices $i$ and $j$ are connected by an undirected edge exactly when the substring from $i$ to $j$ forms a balanced bracket sequence on its own.
We are asked to construct a sequence of positive integers of length $n$ whose sum is fixed to $m$, but with an additional constraint that comes from a peculiar XOR condition applied to value ordering rather than positions.
We are given an array of positive integers. Exactly once, we are allowed to choose a contiguous segment and rotate it cyclically by any amount, which effectively means we can pick any element inside the segment and move it to either end of that segment, while preserving the…
We are given a line of stoves, each carrying an integer temperature that may start negative or positive. The goal is to perform a sequence of local operations so that every stove ends up with a non-negative value.
We are given a directed weighted graph where every edge allows movement in only one direction and has a cost in time. Two tokens, or “hands”, start on different vertices: one is fixed at vertex 1, and the other starts at some vertex p.
We are given an array of integers, each representing the strength of a magical stone. We must split these stones into two equal groups and assign each stone one of two colors.
We are asked to construct a very large hidden array indexed from 1 to N, where N can be up to one billion, without explicitly building it.
The grid in this problem is not arbitrary, it is completely determined by its dimensions. Every cell contains a unique integer, and the numbers increase row by row from left to right.
We are asked to construct, for each test case, a sequence of distinct nonnegative integers, all strictly below $2^{31}$, with a very specific balancing condition.
We are given a collection of axis-aligned rectangles, each defined by its height and width. For every query, we are also given two bounding rectangles: a “small inner constraint” rectangle and a “large outer constraint” rectangle.
We are given a row of people, each either facing left or right. The contribution of a person depends on how many people lie in the direction they are looking.
Each test case describes a small three-player word submission game. Every player independently writes down the same number of short strings, each string having length exactly three. After all words are written, scoring is determined by how many people included each distinct word.
We are given a very small grid with exactly two horizontal strips and some number of vertical columns. Each cell contains one of three colors, but the viewer is colorblind in a specific way: green and blue are indistinguishable, while red remains distinct from both.