brain
tamnd's digital brain — notes, problems, research
41436 notes
We are given a static array and asked to count how many contiguous subarrays satisfy a geometric comparison between two different notions of “spread”.
We are counting integer sequences of length $K$, all entries strictly positive, whose total sum is fixed to $S$. The extra constraint is structural: if you take any contiguous block of length $T$, every such block has exactly the same product.
We are given a set of points on an infinite grid, where each point represents a neuron and is tagged with a color. For each query, we are also given a sequence of colors.
We are playing a game on a sequence of numbers using a deque that starts with a single value, zero. At each step, we process the next array element and are forced to interact with one of the two ends of the deque.
We are given a fixed tree of neighborhoods. Each road is initially controlled by some gang. Over time, roads change ownership: on each day, a specific road is taken over by another gang, meaning that from that day onward its controlling gang changes.
We are given a sequence defined by a recurrence that mixes arithmetic difference, absolute value, and bitwise XOR. The first two values are both 1, and every next value is computed from the previous two using a deterministic rule.
We are given a rectangular grid where each cell has an integer height. Think of this grid as a terrain map. A number of people start at specified cells and can move one step per second in the four cardinal directions, or choose to stay still.
We are given two integer arrays of equal length and we are allowed to pick a contiguous segment from the first array and another contiguous segment from the second array. Both chosen segments must have the same length.
We are given a function defined on non-negative integers where each digit contributes independently through factorials, but with a twist: the function is defined recursively in terms of decimal digits. For a single digit number, the value is simply the factorial of that digit.
We are given an undirected graph where each vertex has a cost and each edge also has a cost. A “trip” is any walk that starts at some vertex, traverses at least one edge, and is not allowed to revisit any vertex or reuse any edge.
We are given a graph of cave rooms plus a special node representing the surface. Each room can potentially be connected to other rooms or directly to the surface through “diggable” edges.
We are given a binary grid made of two symbols, and ., which is not just a picture but a recursive structure. Each maximal connected region of a single symbol forms what the problem calls a data blob.
We are asked to count how many valid sequences of length $N$ can be formed, where each element is an integer between $1$ and $K$. The restriction is on adjacent elements: any two neighbors must be coprime.
We are given a long row of communication towers represented by a binary string. Each character corresponds to one tower in order along a line. A 1 means the tower is on dry ground, either on a shore or an island, while a 0 means the tower sits inside a dangerous cyanide river.
We are given a rooted tree that represents a system of tunnels. Each node is either a cave (a terminal node where bread finally ends up) or a gate (an internal node that forwards bread further downward).
We have a vertical building indexed by floors, where floor 0 is the surface and positive numbers represent increasing depth underground. A person starts at some floor and wants to reach the surface. There is also a lift starting at its own floor.
We are given a positive integer $m$. Think of $m$ as defining a set of “coins”, where each coin is a divisor of $m$. We are allowed to use each divisor at most once, and we try to form sums using these coins.
We are given a sequence of terrace heights laid out on a straight line. Each position represents a terrace of fixed width one, and adjacent positions are effectively contiguous in space. We want to build bridges between selected pairs of terraces.
The maze is a network drawn on several concentric circular rings. Each ring contains up to 360 distinguished angular positions, called principal points, and these are the only places where the crystal can ever be located at the end of a phase.
The input gives a single prime number $P$, which represents the position of the final asteroid, called Silver Star, on a one-dimensional line starting from Mars.
Each input line describes a wine bottle volume written as a decimal number followed by the letter L. Different lines may describe exactly the same quantity even if they look different syntactically, for example 1.0L and 1L represent the same value.
We are given a collection of small polyomino pieces that can be rotated freely and placed on a grid that is exactly 2 cells tall and infinitely long to the right, but in practice we only care about forming a finite 2 × n rectangle.
Two players each control a single combat unit. Each unit repeatedly fires missiles at a fixed interval. A shot does not apply damage instantly, it lands half a second after being fired. Once a unit has fired, it must wait its reload time before it can fire again.
We are given a directed graph where each task is a vertex and each dependency is a directed edge. An edge a - b means task a must be executed before task b.
We are given two rigid structures in the plane: a plug and a socket. Each structure consists of three circular pins or holes. Each circle has a center and a radius, and within each structure the three circles are pairwise disjoint.
We are given a long sequence of integers representing an “urban development index” over time. This array is not static. Two types of operations happen online.
We are given a circular playlist consisting of n songs, each with a fixed duration. Gry listens to the playlist starting from some chosen song i, moves forward through the circle, and stops after exactly n songs have been played.
We are given a set of symbols, each symbol appearing exactly once in a string. From these symbols we choose a subset, and the order of chosen symbols is irrelevant, only which ones are included matters.
We are given a company with $n$ couriers, where $n$ is guaranteed to be divisible by three. Each courier has a strength value, and we must partition all couriers into exactly $k = n/3$ groups, each group containing exactly three people.
We are given a set of fixed positions on the boundary of a unit circular clearing, where each position is described by an angle in degrees. Think of these positions as allowed anchor points where fence posts may be installed.
We are simulating a tap-in tap-out transport system where each passenger uses a numbered travel card. Every event records a pier and a card ID, and events arrive in chronological order.
We are given a tree with (N) nodes. John wants to select disjoint pairs of nodes, with the restriction that a pair is valid only if the distance between the two nodes along the tree is even.
We are given a permutation of size $n$, meaning every integer from 1 to $n$ appears exactly once. For every pair of indices $(l, r)$, we look at the segment of the array from $l$ to $r$.
We are given a rooted tree with root fixed at vertex 1. Every vertex initially contains exactly one biscuit. We will perform exactly k operations. In one operation we pick a vertex x and immediately eat every biscuit that still exists on the simple path from x up to the root.
We are simulating two entities moving along a one-dimensional line of integer points from 1 to N. One of them, Olaf, moves deterministically: every minute he shifts one step to the right.
We are given two arrays of integers, each of length $n$. Every value in both arrays is small, at most $10^3$, but the arrays themselves can be large, up to $2 cdot 10^5$ elements.
We are given a sequence of days, where each day has a base cost for buying a coffee. In addition, there are several coupons, and each coupon has a deadline day and a discount value.
We start with a tree on n vertices. Then we process n − 1 operations in a fixed order given by a permutation of nodes, and after each operation we are asked to count the number of spanning trees in a graph that keeps evolving.
We are given a permutation of size $n$, meaning it contains each number from 1 to $n$ exactly once. We are allowed to perform exactly one swap of any two positions, including the option of swapping a position with itself, which effectively means doing nothing.
We are given an $n times n$ grid, and each cell must be assigned an integer from the range $[0, 4n^2 - 1]$. The assignment is not arbitrary, because two conditions must simultaneously hold. First, no number is allowed to appear more than five times in the whole grid.
We are given a collection of words, but the only property that matters about each word is its length. Each day, Keyi chooses some words to study, and there is a special rule: if she decides to study a word of length $k$, then she must study all words of length $k$ that day.
We maintain a multiset of integers that changes over time, and we must support two kinds of operations efficiently.
We are given a rooted tree whose nodes are labeled from 1 to n, and every node except the root stores a pointer to its parent. The structure is initially static, but it changes over time through operations that modify these parent pointers. Two types of operations occur.
We are given a sequence of positive integers and we are allowed to change values in it. The goal is to transform it so that every pair of adjacent elements sums to a prime number, while changing as few positions as possible.
We are given a grid with a small height but potentially long width. The grid has n rows and m columns. In the first column, every row already contains a distinct “brush” that starts coloring from that cell.
We are given two large integers, $A$ and $B$, which determine a binary string built by a deterministic greedy process. The process starts with zero occurrences of both symbols and repeatedly appends either a 0 or a 1 until exactly $A$ zeros and $B$ ones have been used.
We are given a perfect binary tree whose leaves are numbered in the usual heap style, so the leftmost leaf is 1 and every internal node corresponds to a contiguous segment of leaves. Each query specifies a segment of leaves $[l, r]$.
The process in this problem can be seen as a dynamic race between people and positions on a line of pizza pieces.
We are given a repeating schedule that alternates between work days and rest days. One full pattern consists of a block of x work days followed by y rest days, and then it repeats forever. This means the entire timeline is periodic with period x + y.
We are given an unknown grid of size $n times n$, where each cell contains a distinct integer height. The grid is not visible directly. Instead, we can only query individual coordinates and receive the height at that location.
We are given a collection of rooms connected by doors. Each door can be traversed in both directions, so physically the layout is an undirected connected graph.
We are given a rooted tree with $n$ vertices, numbered from $0$ to $n-1$. Each edge connects a node to its parent, so the input implicitly defines a rooted structure.
We are given a finite rectangular pattern made of four colors, but this pattern is repeated infinitely in both horizontal and vertical directions, forming an infinite tiling of the plane.
We are given four points in the plane, already arranged in clockwise order, and guaranteed to form a strictly convex quadrilateral. Our task is to classify the shape formed by connecting these points in order and closing the cycle. The classification is hierarchical.
There is a queueing system in front of a funicular that runs for a fixed number of minutes during the day. Each minute, a known number of people arrive and join the queue, and immediately after those arrivals are processed, a carriage departs and removes up to a fixed number…
We are given a collection of software packages, each with a known download size. At some moment during an upgrade process, we observe that exactly some number of packages have already fully completed downloading, while up to a fixed number of packages can be downloading at the…
We are given several absolute file paths in a Unix-like filesystem. We are allowed to choose a single working directory anywhere in the tree, but not inside a file.
Codeforces 104791C: Robot
We are simulating a line of people using a water dispenser that is fed by identical buckets, each containing a fixed amount of water. Every person in the queue wants a certain number of liters. The dispenser starts with a full bucket, and people are served one after another.
We are counting binary sequences of length $n$, where each position represents either a win or a loss in a sequence of games. A 1 means a win, a 0 means a loss.
Codeforces 104797B: Building on the Moon
We are given a set of points on a plane, each representing a city. The salesman must produce a single path that visits every city exactly once. He is allowed to start anywhere and finish anywhere, so the result is simply a permutation of all cities.
We are given a linear railway consisting of stations connected in a chain. Between each pair of neighboring stations there is a travel time. Two trains depart simultaneously: one starts at station 1 and moves right, the other starts at station n and moves left.
We are given a long string made only of lowercase letters and a small number of queries over substrings of this string. Each query focuses on a contiguous segment of the string, and asks us to find a very specific pattern inside that segment.
We are given a directed graph of villages connected by roads. Each road connects two villages and comes with a prescribed direction in the input, but we are free to assign a final flow of merchants on each road either in the given direction or in the reverse direction.
We are given an integer grid formed by all lattice points $(i, j)$ where both coordinates range from $0$ to $n-1$. From this set of points, we consider all straight lines in the plane and we want to count how many distinct lines pass through at least two of these grid points.
We are given a radar system that produces a finite set of scanned points in the plane. Each scanned point is formed by choosing a direction and a distance from the origin, then going that distance along that direction.
We are given a rectangular grid that contains lowercase letters and empty cells. Over time, gravity acts on this grid, but not in a fixed direction.
We are given a line of speakers, each speaker has an initial volume and a cost factor that tells us how much energy is needed to change its volume by one unit. Two kinds of operations are performed on contiguous segments of this line.
We are given a sparse grid of
We are given an undirected connected graph that has a restricted structure: every edge belongs to at most one simple cycle, so cycles can overlap only at vertices, not through shared edges. This is the standard definition of a cactus graph.
We are given an undirected graph that is already a tree, meaning there are exactly n nodes and n−1 edges and there is exactly one simple path between any two nodes. The distance between two nodes is the number of edges on this unique path.
We are given a printing shop that splits paper lengths into a sequence of contiguous segments. Each segment represents a range of page counts, and every range has a fixed cost per page.
We are given a string made of Latin uppercase letters and a parameter $k$. A substring is considered valid if it never contains a run of $k$ vowels in a row and never contains a run of $k$ consonants in a row.
We are simulating a very structured drafting process among four players sitting in a fixed cycle. Each round, every player takes exactly one knight token from a common pool until the pool is exhausted.
We are simulating a very simple earning process over a sequence of items called sailors. There are $n$ sailors available in total, and in each of $k$ rounds Igor takes exactly one sailor from what remains.
Each test case describes a collection of resource types gathered during a board game session. For every type, we are given how many units of that resource were collected and how many points a single unit is worth.
We are given a small dictionary of words that Veronica knows, and then a single long string that represents what Igor wrote down as her spoken monologue.
We are given four collections of names. Igor has a list of names he likes and a list of names he dislikes. Ira also has a list of names she likes and a list of names she dislikes. A name is considered usable only if both people like it and neither of them explicitly dislikes it.
We are given a sequence of tower heights placed in a row. Each tower has a numeric height, and we are allowed to pick some of them while preserving their left-to-right order.
We are given a small collection of integers, each between 2 and 15. From this collection, we can repeatedly perform an operation that builds a new multiset by choosing elements from the original collection with repetition allowed.
We are given a rectangular grid that represents a crawling mat. Each cell is either free space, an obstacle, a toy, or Veronica’s starting position. Veronica occupies exactly one cell and also has an initial facing direction indicated by the symbol at that cell.
We are given a diary of how Veronica sleeps during a day. Each diary entry gives a start time when she falls asleep and an end time when she wakes up.
We are given a single integer $n$, and we must decide whether it is possible to construct a square painting of some side length $k$, where $k le n$, under a very specific interpretation of “painting”. The painting is not just a uniform grid of cells.
We are given a single addition written in an unknown numeral system. Three strings represent two addends and their sum, but the base is not provided.
We are given a connected network of cities that forms a tree. Each road connects two cities and has a weight. For any two cities, there is exactly one simple path between them because there are no cycles.
We are working on an infinite 2D integer grid where every lattice point initially has the same default character ".". We are then given a sequence of painting operations that overwrite regions of this grid with new characters.
We are given two permutations of the numbers from 1 to n. The first permutation describes the initial order of a deck of cards from top to bottom, and the second permutation describes the target order we want to achieve.
We are given a large pool of cards split into a small number of types. Type $i$ contains $ai$ distinct cards, and we only care about collecting the first $bi$ distinct cards of that type. A single “refresh” draws one card uniformly from the entire pool.
We are given a graph that is a forest, so every connected component is a tree. The game starts with two players alternating moves, and each move modifies the graph in one of two ways.
I can’t write a correct Codeforces editorial for “104813K - Omniscia Spares None” without the actual problem statement.
We are given a very large $n times m$ grid, but most of it is empty except for a set of $k$ “walls”. Each wall is a vertical segment: it blocks an entire column $y$ from row $x1$ to $x2$. All blocked cells are impassable, and the rest are free cells.
We are given a small weighted undirected graph with up to ten vertices. The weights describe how strongly each pair of planets interacts.
We are given a set of cities, each carrying three independent parameters: Alice can collect some amount of material when visiting, Bob can also collect material when visiting, and each city has a selling value multiplier.
We are given a graph where every positive integer is a node, and for any two nodes $x$ and $y$, the cost of connecting them is determined by the number of distinct prime factors of their least common multiple.
We are given a grid where some cells are open and some are blocked. From a starting open cell, George can attempt to move in the four cardinal directions, but a move only succeeds if the adjacent cell exists and is open; otherwise he stays in place.
We are given two strings of equal length. One string, call it the reference string, defines a collection of patterns: every prefix of this string is a pattern, and each pattern has an associated weight.
We are given a sequence of values representing the happiness gained from a series of contests. After each contest, we want to compute a “memory-weighted mood” that depends on all past contests, but with exponentially decreasing influence for older events.
We are given an initial collection of “knowledge points”, each associated with a positive integer cost representing how many brain cells are required to maintain it. This collection is treated as a multiset, so only the frequencies of equal values matter, not their order.
We are given a large rectangular grid whose height is $2^N$ and width is $2^N - 1$. The grid is not arbitrary: it is built recursively by repeatedly splitting rectangular regions into smaller ones.