brain
tamnd's digital brain — notes, problems, research
43815 notes
We can think of this problem as walking through a sequence of Pokémon, where each Pokémon is a node with a cost to “enter combat” and several strength values across different attributes.
We are interacting with a hidden permutation of numbers from 0 to n-1, but we never see it directly. Instead, we are allowed to compare expressions of the form (p[a] Our goal is not to reconstruct the permutation, but to find two indices i and j such that the XOR of their…
We are given a line of cells, each cell containing a direction character that behaves like a deterministic instruction for a moving token. When a token is dropped onto a cell, it repeatedly moves one step left or right depending on the current cell’s character.
We are dealing with a tree, but the real structure we care about is hidden behind an interactive layer. In every test case, we must output two permutations of node labels.
We build an array incrementally. After every insertion we must compute $$f(a)=maxx left(maxi(aimid x)-mini(aimid x)right).$$ The value inserted at each step is encrypted by the previous answer, so the queries must be processed online.
We are asked to count the number of distinct prefix maximum sequences that can appear over all valid pre-order traversals of a rooted tree.
We are asked to construct a permutation of numbers from 1 to n such that a specific forbidden pattern never appears. The pattern involves two different starting positions i and j.
We are given a binary string, and for each of its substrings, we want to compute the minimum number of ones required to form a “good” string with respect to that substring.
We are given an array a of length n. The task is to repeatedly select an element from a, add its value plus its current index to a set S, remove it from the array, and continue until a is empty. After all insertions, we sort the set S in decreasing order to form array b.
We are asked to count how many ways we can assign integer values to the vertices of a rooted binary tree such that it forms a valid binary search tree, with all values constrained between $1$ and $C$.
We are given a tree with n vertices and a set of k pairs of vertices. Sasha wants to ensure that for each pair (ai, bi), there is at least one colored edge on the simple path connecting ai and bi.
Sasha plays a repeated betting game where each bet either multiplies his stake by a factor or loses it entirely. The only control he has is the size of each bet, and he is allowed to adapt it based on past outcomes.
We are asked to count the number of subsets of intersections in a tree such that, if we declare exactly the intersections in the subset as dangerous, no simple path in the tree contains three or more dangerous intersections.
We have an $n times n$ grid. Every cell belongs to exactly one diagonal of each of the two diagonal directions. The problem counts both directions, so the grid contains a total of $2n-1$ diagonals of one type and $2n-1$ diagonals of the other type, for a total of $4n-2$…
We repeatedly perform the same fold on a square sheet. Each operation folds all four corners to the center, producing a smaller square rotated by $45^circ$. After doing this $N$ times and unfolding the paper, every crease is either a mountain fold or a valley fold.
This is a Type B (prove/disprove) problem. The task is to determine whether a stated property is always true: Given a closed ski track that passes through each village exactly twice, is it always possible to traverse along the track so as to visit each village exactly once?
We are asked to build a single string over the first k lowercase letters such that every possible string of length n formed from those k letters appears somewhere inside it as a subsequence.
We have a line with n positions, each containing a ship. Certain positions have harbours, each with an associated value. Every ship must eventually "move" to the next harbour to its right.
We are asked to construct an $n times n$ matrix of zeros and ones with two simultaneous constraints on the bitwise XORs of rows and columns, and an overall sum constraint.
We are given an array of integers and the ability to decrease each number to any integer between zero and its current value. For positive numbers, this means we can reduce them to zero; for negative numbers, we can increase them toward zero.
We start with an array a of length n. For each of the next d days we must choose exactly one action. The first action increases the prefix [1..bi] by one, where the sequence b is generated by repeating the given array v forever. The second action scores points.
We are building a long array by interleaving two independent permutations in a structured way. One permutation, call it $p$, provides odd base values. The second permutation, $q$, determines powers of two.
Each card can end up in one of three states. A card may be placed in your deck, placed in your friend's deck, or discarded entirely. Let the XOR of your deck be X and the XOR of your friend's deck be Y.
We are working in a geometric setting where a large convex polygon represents a forbidden region. A spaceship starts outside this region and must travel to another point, with the constraint that it is never allowed to enter the interior of the polygon, though touching its…
The network is a tree, so initially there is exactly one simple path between every pair of computers. Each edge, when put into emergency mode, becomes a directed constraint: one endpoint must come before the other in a global ordering of all nodes.
We are given two strings, $A$ of length $N$ and $B$ of length $M$ with $N le M$, representing the names of two twins. We want to create nicknames $A'$ and $B'$ for them.
We are asked to reverse-engineer the merge step of a Merge Sort-like routine, but with a twist: the two input arrays may not be sorted. Concretely, we receive a single array C of length 2N containing every integer from 1 to 2N exactly once.
We have a line of lamps, each either on or off, and a line of buttons, one per lamp. Each button affects only the lamps immediately adjacent to it: pressing button $i$ toggles lamps $i-1$ and $i+1$, if they exist.
We are given a string of lowercase English letters, and our goal is to transform it into a non-decreasing sorted string using a specific operation.
We are asked to work with a segment tree built over an array of length $n$, where the segment tree is the standard binary recursive construction. Each node of the tree corresponds to a segment of the array, and the root node is labeled $1$.
We are given a tree and a special operation. In one operation, we choose any two vertices and look at the unique path between them. Every vertex on that path is merged into a single new vertex.
We are given a permutation of numbers from 0 to n−1. We are allowed to rotate this array cyclically, and for each possible rotation we compute a score as we scan from left to right.
We observe a sequence of match outcomes where each character represents a single play won by either player A or player B. These plays are grouped into sets: a set ends as soon as one player accumulates $X$ wins inside that set.
Working
We are given two sequences. The first sequence is already fixed in its internal order, and we are not allowed to reorder it.
We are given an array of integers and need to construct a parallel array of labels containing only 1, 2, or 3. The goal is to satisfy exactly two out of three pairing conditions, each involving two indices where the original numbers are equal and the assigned labels form one…
We are given an array $b$ of length $n$ and a number $k$, which represents the number of operations performed on some hidden original array $a$. Each operation consists of choosing a fixed point $x$ in $a$ and cyclically left-shifting $a$ by $x$ positions.
We have $n$ cities arranged along a line and a forecast of rain for $m$ consecutive days. Each day's rain covers a continuous interval of cities $[li, ri]$. A city is dry if it never experiences rain across all $m$ days.
We are given a sequence of cities numbered from 1 to $n$ and a forecast of rain for the next $m$ days. On day $i$, rain will cover the cities in the interval $[li, ri]$. A city is dry if no rain ever falls there during the $m$ days. Doremy can prevent rain on exactly two days.
Each stack belongs to a vertex. If we are currently at vertex u, we look at the top element of stack u. If the stack is empty, the process stops and returns u. Otherwise we pop the top element, jump to the vertex written on that element, and repeat.
We are given two binary strings, s and t. Qingshan wants to transform s into a string where no two consecutive characters are the same, called a "good" string. She can repeatedly insert string t anywhere in s, including at the start or end, any number of times.
We are given a binary string consisting only of 0s and 1s. The task is to transform it into a string that satisfies the following "good" property: for every position i in the string, the character at i must differ from the character at the symmetric position counted from the…
We are asked to count the number of ways to colour an array of integers either blue or red, subject to two constraints.
We are given a tree where some edges already have a fixed direction and some edges are still undirected. We must choose directions for the remaining edges and assign a color to every edge. A walk may traverse an edge either along its direction or against it.
We are given a sequence of positive integers indexed from left to right. We are allowed to repeatedly choose positions and “circle” elements. The key twist is that circling does not remove elements immediately; it only marks them.
We choose a value $a{n+1}$ between $0$ and $m$. After that, every earlier position is determined uniquely by $$ai = a{i+1} bmod i$$ for $i=n,n-1,dots,1$. The entire array is generated from a single starting value.
We are given an array indexed from 1 to n. We repeatedly choose a non-empty subset of indices and mark them as special. Those chosen indices are colored black. After that, any still-unselected index becomes green if it is a multiple of at least one black index.
We are tasked with spreading an announcement to all residents of a village in the cheapest way possible. There are two ways to inform residents: Pak Chanek can directly tell someone at a fixed cost p, or a resident who already knows can inform others using a magical helmet…
We are given a collection of green apple pieces, each weighing exactly 1 kilogram. The goal is to distribute these pieces among a fixed number of people so that each person ends up with the same total weight.
The solution correctly restates the exercise in terms of the frequency test and the chi-square statistic for $b$ categories. It identifies the expected value $E(chi^2)=b-1$ and explains why the observed value $1.06$ for the first 2000 decimal digits is unusually small.
We are asked to maximize the time until a bomb explodes. The bomb has a timer b initially, which decreases by 1 every second. You have n tools, each capable of increasing the timer by xi when used, but the timer cannot exceed a maximum value a.
Codeforces 1875E: Jellyfish and Math
We are given an array of nonnegative integers. The task is to remove elements from the array one by one, and after each removal, we add the MEX of the remaining array to a running total. The goal is to minimize this total by choosing the deletion order optimally.
We are asked to simulate a turn-based exchange game between two players, Jellyfish and Gellyfish. Jellyfish owns an array of apples with integer values, and Gellyfish owns a different array.
We are asked to consider a country with $n$ cities connected in a tree-like structure that mirrors a complete binary tree. Each city $i$ has edges to $2i$ and $2i+1$ if those indices do not exceed $n$.
This problem is a Codeforces 3000-rated constructive graph problem. Producing a correct editorial requires reconstructing and proving the entire degree-sequence characterization of flower-like pseudotrees, together with the linear-time construction used in the official solution.
We have a party with n people, each bringing a certain number of candies. Each person can give exactly a power-of-two number of candies to another person, and every person can give to at most one person and receive from at most one person.
For Codeforces 1869A, the entire solution is a constructive observation. If n is even, perform: After the first operation, every element becomes X, where X is the XOR of the whole array.
We are asked to construct an $n times m$ matrix where every row is a permutation of the numbers from $0$ to $m-1$. This means each row contains all values exactly once, but rows can differ from each other. Once the matrix is built, each column induces a multiset of $n$ values.
We have a party with n people, each holding a certain number of candies ai. Each person will give a positive number of candies to exactly one other person, and each person will receive candies from exactly one other person.
The problem presents a magical device called "The Great Equalizer" which takes an array of integers and repeatedly applies a transformation.
We are asked to determine the minimum number of ice cream balls Tema needs to buy to make exactly n distinct two-ball ice cream cones. Each cone consists of two balls, which may be of the same flavor.
We are asked to reconstruct a possible original sequence a given a sequence b that was derived by a simple filtering rule. The sequence b always starts with the first element of a, and then includes every element of a that is greater than or equal to its immediate predecessor.
We are given a rectangular carpet of size $n times m$ where each cell contains a lowercase letter. Vika likes to read her name "vika" from the carpet by selecting one letter from each column, moving strictly left to right, and choosing exactly four columns for the letters 'v'…
We are given a tree on $n$ vertices, where each edge has an integer weight. The task is to count the number of weighted simple graphs such that the given tree is the unique minimum spanning tree (MST), and all edge weights in the graph are integers not exceeding $S$.
The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.
We are given several test cases. In each test case, we start with a list of points placed on a number line. For every point we choose one special position s, and we connect s to every point xi by a segment on the integer line.
We are given two arrays, a and b, both of length n. From these arrays, we are asked to construct a directed graph with n vertices. There is an edge from vertex u to vertex v (for u != v) if the difference a[u] - a[v] is greater than or equal to b[u] - b[v].
The traceback already tells us that the current program is not failing because of the algorithm itself. It is failing because the code is reading the input incorrectly and then indexing past the end of the array.
We are given a number written as a string of digits, and we are allowed to repeatedly apply a specific rounding operation that changes digits at a chosen position and propagates carry to higher positions in a non-standard way.
We are given an array of integers and need to decide whether it can be partitioned into two non-empty groups such that the sums of each group have the same parity-both even or both odd. Each group must contain at least one element.
Petya walks past benches numbered from 1 to n. Some benches contain cookie sellers. Whenever Petya reaches a bench, he eats a cookie if one of three things is true: 1. The bench contains a seller, in which case he immediately buys and eats a cookie. 2. He has never eaten before.
We are given a binary string representing a row of trees, where each position is either an oak or a fir. The quality of a final arrangement depends only on two numbers: the longest consecutive block of zeros and the longest consecutive block of ones.
We are asked to maintain a dynamic array while processing four types of queries: append a number, remove the last $k$ numbers, roll back the last change (append or remove), and report the number of distinct numbers in the array. The array is initially empty.
We are asked to maintain an array under four types of operations: appending an element, removing the last $k$ elements, rolling back the last change (which could be either an append or a removal), and querying the number of distinct elements currently in the array.
We are asked to construct permutations of integers from 1 to $n$ in such a way that, when we compute the greatest common divisor (GCD) between consecutive elements (with wrap-around), the number of distinct GCD values is maximized.
Two players alternate turns removing objects from a shared pool. Each object is a “button” with a restriction: some buttons can only be taken by Anna, some only by Katie, and some are flexible and can be taken by either player.
A closed broken line with six segments is a hexagonal cycle whose six vertices lie on one circle.
We are given two arrays of length $n$, $a$ and $b$. For any contiguous subarray, or segment, defined by its start $l$ and end $r$, we can compute a "cost" using the formula $ The problem is subtle because segment costs depend on both ends of the segment and both arrays.
We are asked to model escape paths in a one-dimensional world where Andrey can use portals repeatedly. Each portal is a segment [li, ri] from which Andrey can enter and teleport to another contained segment [ai, bi].
We are given a tree with n cities connected by roads. Each road has a hardness value wi. The travel time along a road depends on the driver’s skill c and is calculated as ceil(wi / c).
We are given a permutation of the numbers from 1 to n. For a permutation p, define $$text{cost}(p)=sum{i=1}^{n} pi cdot i-max{i=1}^{n}(picdot i).$$ The task is to find the largest possible value of this expression among all permutations of length n.
We are given multiple arrays, each containing at least two positive integers. We are allowed to move at most one number from each array to some other array. After these moves, the “beauty” of the collection is defined as the sum of the smallest element in each array.
We are given an array of integers, and our goal is to split it into two non-empty arrays, b and c, such that no element in c divides any element in b. Each element must go into exactly one array. If this is impossible, we return -1.
We are given a string and a cursor that initially sits between two letters. The cursor can move left or right by one position, and it can also "teleport" between any two adjacent letters x and y if there exists another pair x followed by y elsewhere in the string.
We are given $2n$ tuples of the form $(a, b, c)$, where $a$ and $b$ are positive integers and $c$ is a bracket, either '(' or ')'. Exactly half of the tuples are opening brackets and the other half are closing brackets.
We are given a binary string, and we are allowed to reorder it using swaps between any two positions. The cost of each operation is one swap, and swaps are unrestricted in the sense that we can choose any pair of indices.
We are given a string s consisting only of parentheses, and we need to construct a new string t of length exactly twice that of s, such that t forms a valid bracket sequence and s does not appear anywhere inside t as a contiguous substring.
We are given a permutation and a game played on its positions. The chip starts nowhere. Alice begins by choosing any position and placing the chip there. After that, players alternate moving the chip.
We are asked to determine the minimum number of fancy coins Monocarp must use to pay exactly m burles when he has two types of coins: one worth 1 burle and one worth k burles.
In this problem, we have a card game with multiple players and a dealer. Each card belongs to one of four suits. The dealer has already partially dealt cards to players, and some cards remain in the deck.
We are asked to consider arrays of length n filled with integers from 1 to k. The "cost" of an array is defined as the maximum number of contiguous subarrays of length exactly k where each subarray contains all integers from 1 to k exactly once, and no element participates in…
We are given an array of positive integers, and our task is to transform it into a strictly increasing sequence using the fewest operations.
We are asked to check whether a given sequence of symbols could have been produced by operations on an array that starts empty.
We are given two binary strings of equal length. Both strings always start with a 0 and end with a 1. We are allowed to repeatedly apply an operation that takes a segment inside one string, provided the endpoints of that segment contain the same character, and then forces…
We start with a fixed multiset of digits from 1 to 9, each appearing exactly once, written in a row. The only operation allowed is deleting digits one by one, with the restriction that we are not allowed to delete when only two digits remain in the current sequence.
We are asked to calculate the minimum time Vika, a sorceress, needs to defeat a sequence of monsters. Each monster has a strength, and Vika has two types of magic-water and fire. In one second, she generates fixed amounts of water and fire mana.
Kolya wants to visit a movie theatre over n consecutive days, each day showing a new movie. Each movie has a raw entertainment value a[i], but the enjoyment Kolya actually gains is reduced by how long he has waited since his last visit.
We are given a sequence of fence planks, each with a height, already sorted in non-increasing order. Anya wants to know if the fence is symmetrical when viewed as a grid of unit blocks.
We are given a tree, so between any two vertices there is exactly one simple path. From this tree we want to choose several distinct vertex-sets, where each chosen set must itself be the vertex set of some simple path that contains at least two vertices.