brain
tamnd's digital brain — notes, problems, research
41556 notes
We are given an $n times n$ table that was originally constructed from an unknown sequence $a1, a2, ldots, an$. Every off-diagonal cell contains the product of two elements of this sequence, specifically $B{i,j} = ai cdot aj$ for $i neq j$.
We are given a string s that contains lowercase letters and wildcard characters ?, and another string t consisting only of lowercase letters. Before anything else happens, all ? characters in s must be replaced by lowercase letters chosen by us.
We are given two kinds of words. One group contains short words, all of equal length a, and there are n distinct words of this type. The other group contains long words, all of equal length b, and there are m distinct words of this type, with a < b.
We are given a single line string that is meant to represent an arithmetic equality between two expressions. Each expression can contain decimal digits and the symbols + and -.
We are looking at a two-player impartial game played on a single pile of stones. The game starts with $N$ stones, and players alternate turns. On a turn, the current player removes between $1$ and $K$ stones inclusive.
We are given a set of points in the plane and asked to reconstruct the boundary of their convex hull in two different levels of detail.
We are playing a two-player take-away game with a single pile of stones. Players alternate turns, and on each turn a player removes between 1 and K stones inclusive.
We are given a list of scientific papers, each with a current citation count. The Hirsch index we want to reach is a threshold H, which means we need at least H papers whose citation counts are each at least H.
We are asked to count integers in a range $[a, b]$ such that each integer has exactly seven positive divisors. The task is not about factoring arbitrary numbers efficiently online, but about understanding the structure of numbers whose divisor function equals seven.
We can view the factory as a directed graph on $N$ workshops. Every workshop from $1$ to $N-1$ already has exactly one outgoing conveyor, so each of these nodes points to a fixed next node. Workshop $N$ is newly introduced and initially has no outgoing conveyor.
We are given a positive integer $n$, and we conceptually form a huge product where each integer $i$ from 1 to $n$ is raised to its own power $i$, and all these values are multiplied together: $$1^1 cdot 2^2 cdot 3^3 cdots n^n$$ The task is not to compute this enormous number…
We are simulating a simplified virtual memory system where pages can either be in fast physical memory or stored on disk. At the start, the first m pages are already loaded into physical memory, and the remaining pages are on disk. Then a sequence of k page accesses is executed.
We are given an $n times n$ chessboard and a bishop placed on a starting square. The bishop can move any number of cells in a single move, but only along diagonals.
We are working with correctly balanced parentheses strings of length $2n$. Such a string can be thought of as a sequence of $n$ opening brackets and $n$ closing brackets arranged so that at every prefix, openings are never outnumbered by closings, and at the end the counts match.
We are asked to build a generator that outputs pairs of integers $(a, b)$ satisfying $1 le a le b le k$, and each valid pair must be produced with equal probability whenever we request a new value.
We are given a final set of species labeled from 1 to n, where label corresponds to fitness and also to the order constraint that parents always have smaller labels than children.
We are given the current snapshot of all bacteria that are alive on an infinite integer grid. We are told that originally there was a single bacterium at some unknown grid point, and after some unknown number of minutes, bacteria spread through Manhattan-adjacent moves.
We start with a single circular RNA string made of four possible characters. Over time, this structure is transformed by two kinds of operations that interact in a very specific way.
We are given a linear habitat made of forests, each forest having a numeric “resistance” value. A wildfire can start at a chosen forest with some initial integer strength and then spread left and right across adjacent forests.
We are given a sequence of tasks ordered by priority from first to last, and each task consumes a fixed amount of ATP to complete. Jasmine has a daily ATP budget of $m$, and she cannot repeat tasks. The twist is that she does not always consider all tasks.
We are given two DNA strings of equal length, composed only of the characters A, T, C, and G. Each position represents a nucleotide, and we are asked to decide whether the second string can be obtained from the first using only mutations that swap complementary bases.
We are given a layered structure where each layer contains a certain number of nodes. Between every pair of consecutive layers, every node in the left layer is connected to every node in the right layer.
A cell starts with c chromosomes and divides into two daughter cells containing a and b chromosomes. The division is considered correct only if every chromosome ends up in exactly one of the two daughter cells.
We are given a directed graph whose edges are labeled with decimal digits. Starting from vertex 1, we may walk forever by following directed edges. The sequence of edge labels becomes the decimal expansion of a number between 0 and 1.
We are given a partially specified array of length $N$, where each position is either fixed to one of the values $1,2,3$ or is a wildcard that can be replaced independently by any of the three values. Every full assignment produces a concrete integer array.
We are given several independent test cases. Each test case describes a set of shooting lanes, where lane i contains Ai targets arranged in a line. Tim will fire a sequence of shots, and each shot is assigned to exactly one lane.
Each clause is the product of three variables, where every variable is either 0 or 1. The whole expression is the sum of all clause values. We are asked whether there is an assignment of the variables such that this sum is odd.
We are given a multiset of integers representing letters, where each value from 1 up to NM is just a symbol in a totally ordered alphabet. The task is to split all these symbols into N words, each word having exactly M letters, using every occurrence exactly once.
For each test case, we are given an array of integers. We must construct the smallest positive integer m such that every array element shares a common divisor greater than 1 with m. In other words, for every value ai, the greatest common divisor gcd(ai, m) must be at least 2.
The system we are validating is extremely simple: for each test case, we are told how many tests a program was supposed to run and how many of them it actually passed. From this, we decide whether the program fully succeeded or not.
We are given a binary string, and we are allowed to take any contiguous segment of it. Each such segment is interpreted as a binary number, and we want to know whether at least one of these numbers is a prime.
We are given an integer starting point and a forbidden digit. From the starting number, we are allowed to repeatedly increase it by one. The goal is to reach the first number at or after the starting point whose decimal representation does not contain the forbidden digit at all.
For each test case, we are given a positive integer n. We must count how many positive integers in the range from 1 to n have an odd number of decimal digits. The value of n can be as large as 10^18. That immediately rules out any solution that examines every number individually.
Each test case gives a collection of juice bottles, where the i-th bottle contains a certain number of liters. Abdelaleem will serve exactly m friends, and for each chosen bottle he is allowed to pour the same integer amount of liters into every friend’s cup.
We are given an array and asked to think about all ways to choose exactly k elements while preserving order, although the order constraint does not affect which values end up selected, only which subsets are valid.
We are simulating a small training management system that keeps track of students and their accumulated bonus points. Each student has a fixed identity given by an index from 1 to n and an associated name. Initially, all students start with zero points.
We are given three integers $l$, $r$, and $k$. The task is to count how many integers $x$ in the range $[l, r]$ satisfy a condition derived from a digit-selection construction: the number $x$ must be representable as a concatenation of chosen “digits”, where each chosen…
We maintain a mutable string over lowercase letters. Two operations are supported: point updates that overwrite a single position, and queries over a substring asking whether that segment can be turned into a palindrome after changing at most one character inside the segment.
Let $\rho(x)$ denote the number of trailing zero bits of $x$, that is, the number of right shifts required until the least significant bit becomes $1$.
Each test case describes a right-angled triangle using its base and height. The task is not to compute the actual geometric area, but instead to output twice that area. A right triangle’s area is computed as half of the product of its base and height.
Let $i$ be the index, $0 \le i < 12\cdot 10^6$, and write q = \left\lfloor \frac{i}{12} \right\rfloor,\qquad r = i - 12q,\qquad 0 \le r < 12.
We are given two equal-length strings over the lowercase alphabet. The allowed move is not a local edit but a global relabeling: we pick two distinct letters, and every occurrence of those two letters in the string is swapped simultaneously.
We are given two sequences, each a permutation of the same set of integers from 1 to n. The task is to find the length of the longest subsequence that appears in both permutations and is strictly increasing.
We are given a tree with n vertices, each vertex carrying a non-negative weight. We need to split the vertices into disjoint groups, where each group must form a simple path in the tree, and no vertex can belong to more than one group.
We are given a multiset of positive integer weights representing soldiers. The only operation allowed is to take two soldiers whose strengths differ by exactly one and replace them with a single soldier whose strength is their sum.
We are given a sequence of integers from 1 to n placed in a row. Two players alternate moves, starting with the first player.
We are given a positive integer $k$, describing a stack of $k$ consecutive square layers. The base layer contains $n^2$ cannonballs, the next contains $(n+1)^2$, and so on up to $(n+k-1)^2$. The total number of cannonballs is therefore the sum of these $k$ consecutive squares.
We are interacting with a hidden positive integer $x$. Instead of seeing it directly, we can submit queries with a number $q$, and the judge replies with a value derived from the integer $leftlfloor frac{x}{q} rightrfloor$.
We are given a rectangular grid where each cell behaves like a directed system. Most cells are normal, meaning stepping onto them simply costs one hour per move.
We are moving on a graph whose vertices are integers greater than 1. From any integer $u$, we may move to any other integer $v$, and the cost of that move is $mathrm{lcm}(u, v)$.
The input describes a set of axis-aligned rectangles on an infinite grid. After applying all of them, every grid cell covered by at least one rectangle becomes “bare”.
We are given an ordered set of points on a number line. At each step, Bob picks two adjacent points in the current ordering, removes them, and inserts their midpoint.
We are asked to construct a permutation of the numbers from 1 to n such that a particular cost expression becomes as small as possible.
Working
We are dealing with a hidden binary string of length n. We cannot see it directly. Instead, we are allowed to submit a constructed binary string T of the same length, and the judge returns a single number: the count of positions where S XOR T equals zero.
Working
The structure is a rooted tree with node 1 acting as the root, but conceptually it is drawn upside down so that gravity pushes objects toward the root. Each node can hold at most one ball. We are given a sequence of starting nodes, and we drop balls one by one.
We are given a binary string and two ways to modify it, each with a cost. The goal is to transform the string into a “good” form where no adjacent pair of characters differs.
We are simulating a simplified cricket scoring system where each ball contributes a fixed amount of runs. The batsman can only score either 4 or 6 runs per ball, and we want to reach at least a target score $n$.
The statement you provided is effectively empty beyond the contest header, so there is no information about the task itself (no input format, no required output, no constraints, and no problem definition).
We are given a collection of water reservoirs. Each reservoir has a fixed capacity and a current amount of water stored inside it. The operation allowed is very specific: we may choose at most two reservoirs, say i and j, and pour all water from j into i.
Solution to TAOCP 7.1.3 Exercise 215.
A complete branchless solution must make the pivot selection explicit.
Let $a = (a_{63}\dots a_1 a_0)_2,\qquad b = (b_{63}\dots b_1 b_0)_2,$ and interpret them as polynomials over $\mathbb{F}_2$, $a(x)=\sum_{i=0}^{63} a_i x^i,\qquad b(x)=\sum_{j=0}^{63} b_j x^j.$ The pro...
Index the $64$ entries of $f$ by vectors $x = (x_1,\dots,x_6) \in {0,1}^6$, and write \hat f(x) = \bigvee_{y \le x} f(y), where $y \le x$ means $y_i \le x_i$ for all $i$, so $\hat f$ is the least mono...
Let $x$ contain $8j+k$ with $0 \le j,k < 8$.
The earlier solution fails because it tries to reconstruct hidden structure using $y \mathbin{\&} (-y)$, which only isolates the least significant 1-bit and does not encode any run length information.
The solution must address the actual object in Exercise 36, namely the suffix parity transformation $x^{\oplus}$, and relate it to what MXOR can compute.
The previous construction fails because it tries to realize the transpose as swaps at fixed index distances in the full 64-bit linearization.
We are given a string made only of digits 2, 3, 4, and 5, which represents a sequence of grades in a school journal. We are allowed to modify any character, but only by increasing its value, never decreasing it.
We are given a directed structure where each story points to exactly one other story. Formally, each index i has a single outgoing edge to a[i]. We also have a binary array b, where b[i] = 1 means Bunga believes story i was told, and b[i] = 0 means he believes it was not told.
We are simulating a process where shirts arrive one by one from the top of a stack and are placed onto a linear hanger with positions from 1 to n.
We are given a multiset of $2n-1$ positive integer weights, representing cheese pieces. We are allowed to choose exactly one of these pieces and cut it into two positive real parts. After this operation, we have exactly $2n$ pieces in total.
We are given a vertical stack of circular bread slices, all centered on the same vertical line. Each slice is a cylinder of height 1 and radius r[i]. The first slice touches the table, the second sits on top of the first, and so on.
We are placing rooks on an $n times n$ chessboard, but unlike the classical rook-placement problem, we are allowed to tolerate conflicts. A rook attacks along its row and column, so two rooks in the same row or column attack each other.
We are given a multiset of points placed on a number line. At each step, we repeatedly pick any two existing points, remove them, and insert their midpoint. This continues until only one point remains, and the process stops.
We are given a fixed tree, and every vertex starts in one of two states that change over time. Initially, all vertices are white. Each operation selects two vertices and paints every vertex on the unique path between them black. Once a vertex becomes black, it never changes back.
We are given a large grid, but only a small number of cells actually contain fish. Each such cell can contain up to three fish.
We are simulating a simplified Go game on a fixed 19×19 grid, where stones are added one by one and never removed except when they become “dead”.
We are given an array of integers where each value represents the initial level of an enchanted book. Books are placed in a fixed order, and several types of operations are performed over this array.
We are given a sequence of chapter costs, and we must split this sequence into at most $k$ contiguous segments, where each segment corresponds to a day of reading.
Each test case describes a simple catering plan for a programming contest. There are $n$ contestants in total. Exactly $x$ of them choose a grilled chicken burger set, while the remaining $n - x$ choose a spicy chicken burger set.
We are given two positive integers $x$ and $y$. From these two values we compute their greatest common divisor and least common multiple, and then form a derived quantity that combines them through a square root.
We are given several independent test cases. In each one, we receive up to 100 points on a 2D plane. From these points, we are allowed to choose any subset and look at the convex polygon formed by the chosen points as its vertices.
The original solution fails because it does not implement the correct byte insertion into the polynomial register and therefore does not preserve the CRC invariant.
We are given a geometric graph where each vertex is a point on a plane and edges connect some pairs of these points. The edges are guaranteed to form a forest, so each connected component is already a tree in the full graph. We then take a random axis-aligned rectangle.
The grid describes a floor plan where each boundary segment between cells can either be a fabric wall or a normal wall. Lorenzo is initially stuck on one specific fabric wall segment, meaning he is attached to a particular cell boundary with a known orientation.
We are given a set of competing teams in a contest. Each existing team has three attributes: their strength, their weight, and the difficulty of the problem they contributed.
We are given a group of people, each with a target final value $ai$. Initially every person starts at zero. There is a global operation that is applied in steps: each time the group “takes a shot”, every person updates their current value using the same rule.
We are given a line of slot machines, each containing some number of stones. For any contiguous segment of machines, indexed from l to r, a two-player game is played on that segment.
We are given a sequence of operations that simulate a very simple memory system. Each variable is allocated exactly once using a let X = new(); statement, and later released exactly once using drop(X);.
We are given a timeline of production that is already split into disjoint time intervals. Each interval produces containers of a single product type, and during every unit of time inside that interval exactly one container appears.
We are given a circular cake centered at the origin with a fixed radius. Inside this cake, there are several candles placed at integer coordinates, and every candle lies strictly inside or on the boundary of the circle.
We are given a directed graph with $n$ nodes and $m$ unit-length edges. We also have $k$ independent construction teams.
We are given a row of vertical pillars of width 1, each with a distinct height. At both ends of the row there are imaginary pillars of infinite height, which act like absolute walls. For each query, water is dropped from infinitely high above a chosen pillar.
We are given a binary string and allowed to repeatedly perform a very flexible operation: pick any contiguous segment and rotate it cyclically.
We are given two types of items. There are n items of type A, each contributing value a, and m items of type B, each contributing value b. We want to repeatedly assemble identical “products”.
We are given a hidden $n times n$ grid filled with positive integers in the range $[1, n^2]$. The grid is not arbitrary: values are monotone in both directions, meaning they never decrease as we move right or down.
We are given a tree where a “fake message” starts at a fixed node $r$ and spreads outward one edge per unit time. At time $t$, every node within distance at most $t$ from $r$ has received it, so the infected set is exactly a metric ball centered at $r$.
We are standing on a line of seats, each seat holding a non-negative value. From a chosen starting seat, we may move left, right, or stay in place once per second. Whenever we land on a seat for the first time, we collect its value. Re-visiting a seat later gives nothing new.