brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given several independent test cases. In each test case, we start with an array of positive integers. We are allowed to repeatedly pick two different positions and move a multiplicative factor from one value to the other, but the factor must be a divisor of the first…
We start with a string x. One operation replaces x with x + x, meaning the current string is appended to itself and its length doubles. We are also given a target string s.
We are given an $n times n$ matrix of lowercase letters, where $n$ is even. The goal is to transform the matrix into a "perfect square," which is defined as a matrix that remains unchanged when rotated $90^circ$ clockwise.
We are given three positive integers, each representing the length of a thread. In one move, we pick a single thread and split it into two smaller threads with integer lengths, both strictly positive, and their sum equal to the original length.
We have a deck of cards, each containing an integer value. During the game we repeatedly remove cards from the current deck. If we remove a card at an odd position, its value is added to our score.
We are given two independent permutations, one of length $n$ and another of length $m$. We repeatedly apply a synchronized operation: in each step we choose a position in each array, then rotate each array so that the chosen element becomes the last element, preserving…
We are given two permutations, one of size $n$ and one of size $m$, which are simply arrays containing all integers from 1 to $n$ and 1 to $m$ in some order. The goal is to transform both permutations into their sorted forms simultaneously, using a specific operation.
We are given several sets of integers. We can choose any subset of these sets (including none) and take the union of the selected sets. A set is attainable if it can be formed in this way.
We have a tree where each vertex contains a number. After choosing a root, we may repeatedly pick a vertex and XOR every value inside its subtree by some non-negative integer c. Applying such a spell costs (subtree size) × c.
We need to construct a new sequence $b$ of length $n$. Every element of $b$ must be a positive integer. The sequence must be strictly increasing, and for every position $i$, we are forbidden from choosing $bi = ai$.
We have two arrays of the same size. Before doing anything else, we may reorder each array arbitrarily. An operation removes one element from the first array and one element from the second array.
We are given an array and a small integer $k$, where $2 le k le 5$. In one operation we may pick any element and increase it by one. The task is to find the smallest number of operations needed so that the product of all array elements becomes divisible by $k$.
We are given an array of integers and are asked to count the number of contiguous subarrays whose elements appear as a subsequence in the original array exactly once.
We are given two arrays, a and b, each of size n. We are allowed to remove elements from both arrays in pairs, and before doing so, we can reorder the arrays arbitrarily.
We are asked to maintain a dynamic multiset of segments on the number line, processing additions and deletions one by one. After each operation, we must determine whether the multiset contains at least two segments that do not overlap.
We are given an array of integers, and our task is to transform it into a non-decreasing sequence using the minimum number of operations. The operation allowed is doubling a single element any number of times.
We are asked to enter a four-digit PIN on a device where the digits are arranged in a circle from 0 to 9. The cursor starts at 1. Each second, we can either press the current digit or move the cursor to an adjacent digit.
We are asked to determine whether a string can be reduced to a palindrome after removing exactly k characters. The string consists only of lowercase letters, and the number of characters to remove is strictly less than the string length.
We are given an array of integers and the ability to increment a contiguous segment of the array in a single operation. Each operation has a cost measured as the square of the segment's length, and we earn coins equal to this cost.
We are given an array of integers a[1..n], each between 1 and n. We need to count the number of pairs (i, j) with i < j such that there is no k for which both a[i] and a[j] are divisible by a[k].
We are given a binary number as a string of length $n$, which may contain leading zeroes. The task is to determine, for each integer $i$ from 1 to $n$, the minimum number of adjacent swaps required to make the number divisible by $2^i$, or indicate if it is impossible.
We are given a very long array, initially all zeros, and a collection of segments on this array. Each segment, if chosen, adds one to every position inside its interval. We are allowed to choose any subset of segments.
For each test case, we are given a starting number x and an integer k. A number is considered beautiful if the sum of its decimal digits is divisible by k. The task is to find the smallest integer y such that y ≥ x and the digit sum of y is divisible by k.
Place the four collinear points on the $x$ axis as
This is not a traditional optimization problem where the judge checks whether you found the best answer. The statement describes a very complicated wireless scheduling model involving users, cells, time slots, frequency blocks, power allocation, interference, frame deadlines…
Each camera can be hacked multiple times. A hack performed at second T disables that camera during the interval [T + 1, T + s]. The only moments that matter are the two thefts. Let the first diamond be stolen at time A and the second at time B, with A < B.
We are given a set of programmers, each with a stress tolerance level, and a set of projects, each with a difficulty.
Think about the process in reverse. Instead of starting with an empty set and inserting numbers, start with the full set {1,2,…,n} and repeatedly remove one number until only one number remains.
We are given an integer $n$ and must split it into three numbers whose sum is exactly $n$. The three numbers must satisfy three conditions simultaneously. They must all be positive, they must all be distinct, and none of them may be divisible by $3$.
We are given a string and asked to generate a sequence of strings by removing exactly one character at a time to make the resulting string lexicographically minimal.
Monocarp starts at the origin $(0,0)$ and wants to reach his home at point $P$. The only illuminated regions come from two lanterns located at points $A$ and $B$. Both lanterns must use the same power $w$, which means each lantern illuminates a disk of radius $w$.
We are given a sequence of integers r1, r2, ..., rn, called the characteristic of some unknown sequence a1, a2, ..., an of length n.
We are asked to interact with a grid of size $n times n$. Initially, $2n$ cells are pre-colored with unique colors from $1$ to $2n$, and the rest are uncolored. In each of up to 10 allowed moves, we can request Alice to color a previously uncolored cell.
We are given an array of distinct integers ranging from 1 to n, and we are asked to answer multiple queries about contiguous subarrays.
We are given an array of integers and a sequence of operations that increment segments of the array by a given value. Each operation specifies a contiguous subarray and an integer to add.
We are given a fixed set of cities and a sequence of historical snapshots. Each snapshot describes which roads exist between cities at that moment in time. These road systems change completely from one snapshot to another.
I can't reliably write a complete correct editorial for CF 1889F from the problem statement alone. This is a 3500-rated problem, and the official editorial page no longer exposes the written explanation.
We are given two trees on the same labeled vertex set. The labels are fixed and unique, so each node identity is global across both trees.
We are given a collection of $n$ stacks, each containing integers between $1$ and $n$. For each position $i$, we define a function that repeatedly moves to the stack indicated by the top element of the current stack, popping that top element, until it reaches an empty stack.
We are given a line of cities and a sequence of rainy days. Each day paints a contiguous segment of cities with rain, and a city is considered dry only if none of the days ever cover it. On top of this fixed schedule, we are allowed to “cancel” exactly $k$ of the rainy days.
We are given a binary string and allowed to modify it by repeatedly inserting the fixed substring 01 at arbitrary positions. Each insertion increases the length by two characters and keeps all existing characters intact, only shifting them.
We are asked to find how many cities can be made completely dry over a sequence of days, given that on each day a contiguous segment of cities receives rain. Doremy has a special ability: she can cancel the rain on exactly two of these days.
We are given a set of cities, each city having a non-negative weight representing population. Initially, there are no connections between any cities.
We are given several test cases, each consisting of an array of positive integers. The task is not to construct a new array from scratch but to decide whether we can reorder the given elements so that every pair of adjacent elements in the resulting sequence has the same sum.
We are asked to process a sequence of operations on a growing rooted tree. The tree starts with a single node numbered 1, and each node has a numerical value, initially 0.
We are given a sequence of exams with known difficulties. Smilo considers consecutive exams with coprime difficulties unpleasant. The "sadness" of the year is the total number of consecutive exam pairs whose greatest common divisor is one.
We are given an array of integers, and the only operation allowed is a kind of prefix subtraction. Specifically, you can pick a prefix of length $2^m$ for any non-negative integer $m$ such that $2^m le n$, and subtract 1 from every element in that prefix.
Working
We are given several independent scenarios. In each scenario, there are multiple groups of enemies, each group having some initial size.
We have an array of positive integers and a sequence of queries. A query with value x examines every array element. If an element is divisible by 2^x, we add 2^(x-1) to that element.
We are asked to assign weights from 1 to 3 to every vertex and edge of a graph that is connected and has a very particular structure: any two simple cycles are vertex-disjoint.
We are given a multiset of colored cubes. Cube colors are fixed, but we may choose how to distribute them across shelves and in what order they appear on each shelf. For a shelf, the requirement is about the minimum distance between equal colors.
Working
We are given two arrays. The first array is fixed in order, and the second array is a multiset of extra values we are allowed to insert anywhere into the first array, while also being allowed to permute these inserted values arbitrarily before placing them.
Working
We are given a binary string where each position carries a value depending on how we color it. Every character can be painted either red or blue. If we choose red at position $i$, we earn $ri$. If we choose blue, we earn $bi$.
Let the common intersection point of the altitudes be $H$.
We are given the XOR values between consecutive elements of an unknown permutation. Let the required permutation be $b$. For every adjacent pair, we know $$bi oplus b{i+1} = ai.$$ The array $b$ must contain every integer from $0$ to $n-1$ exactly once.
We are counting arrays of length n consisting of non-negative integers. Adjacent values may move by at most k in either direction. An array is considered fancy if at least one element belongs to the interval $$[x, x+k-1].$$ The task is to count all such arrays modulo $10^9+7$.
Each test case describes two players who each own a fixed set of cards. Every card has two numbers, an attack and a defence. A card can defeat another card if its attack is strictly greater than the other card’s defence. The game starts when Monocarp chooses one of his cards.
The number line contains three important positions. Monocarp starts at position 0, the chest is at position x, and the key is at position y. To open the chest, Monocarp must eventually be standing at the same position as the chest while already carrying the key.
We start with a multiset of $2n$ integers. The task is to use every number exactly once and pair them up, forming $n$ ordered pairs. Each pair becomes a point in the plane, where the two values are interpreted as its $x$ and $y$ coordinates.
We are given a collection of ticket fragments, each represented as a string of digits from 1 to 9. A lucky ticket is defined as a string of even length where the sum of digits in the first half equals the sum in the second half.
There are $n^2$ racers with distinct speeds. A race may contain exactly $n$ racers, and the only information returned is the winner of that race.
We are given two binary strings, both of length $2^{k+1}$. Some positions are fixed as 0 or 1, while others are unknown and marked with a question mark.
Let $n = 2^{k+1}$. We must fill the question marks in two binary strings $s$ and $t$, each of length $n$, so that both strings contain exactly $n/2$ zeros and $n/2$ ones. The second condition is much more interesting.
Working
We are given an array consisting only of 1s and 2s, and the array changes over time. Between changes, we are repeatedly asked a yes/no question: whether there exists a contiguous subarray whose sum is exactly some target value. The key difficulty is that the array is not static.
We are given a permutation of 1...n. Some positions are already correct, meaning a[i] = i. These positions are called good. Every second, we look only at the positions that are still not good. Their values are cyclically shifted one step to the right among those positions.
We have two arrays of equal length. Array a is fixed, while array b may be rearranged arbitrarily. After choosing a permutation of b, we compare the arrays position by position. The beauty of the resulting pair of arrays is the number of indices where a[i] b[i].
We are given a permutation and a very specific swap operation. A swap is allowed only at a position i where the element is a local maximum. In other words, a[i] must be larger than both of its neighbors.
We are given a string consisting only of two characters, A and B, which can be thought of as a line of adjacent tiles. The only allowed move is to pick a position where an A is immediately followed by a B, and swap them so that the A moves one step to the right.
We are given an $n times m$ grid representing a room where Vova is trapped. Each cell is either empty, blocked, or contains Vova. He can move to any empty cell sharing a side, and he can escape if he reaches an empty cell on the boundary of the grid.
We are given two strings, s and t. The task is to determine whether it is possible to transform s into t using two operations: removing any character from s or sorting any substring of s alphabetically.
We are asked to color the segments of a rectangular grid, formed by $n$ horizontal lines and $m$ vertical lines, using two colors, red and blue. Each segment connects two adjacent points either horizontally or vertically.
We are given a string consisting only of the characters A and B. The goal is to transform this string so that it contains exactly k occurrences of B.
We start with an array of positive integers. The only allowed operation is to pick one element and split it into two positive parts whose sum equals the original value. Each split increases the array length by one.
We are given a tree with $n$ nodes, but the tree is not fixed in its usefulness. Over $q$ days, a value $di$ is announced, and each day we must ensure that the current tree contains at least one pair of leaves whose distance is exactly $di$.
We have a rooted tree with root at vertex 1. A permutation p contains every vertex exactly once. Each query gives three values (l, r, x). We look at the vertices appearing in the permutation segment p[l...
We are given an array of integers, and we want to sort it in non-decreasing order. The catch is that we cannot arbitrarily swap elements.
We are given a sequence of integers a1, a2, ..., an, where each integer represents the exponent of 2 forming a musical note: bi = 2^{ai}. Yarik defines a combination of two notes (bi, bj) as bi^{bj}.
The problem asks us to find the maximum possible weight difference between two trucks when loading boxes of TNT. We have a row of boxes with given weights, and we can choose any truck size $k$ from 1 to $n$ as long as it divides $n$.
We are given several independent test cases. Each test case provides an integer array, and the task is to choose a non-empty contiguous segment whose sum is as large as possible, under one additional restriction: adjacent elements inside the chosen segment must alternate in…
We are asked to analyze a simple two-player game with integers. The game starts with a number $n$. Vanya moves first, and each player can either increment or decrement the number by 1 on their turn. Vanya wins immediately if, after his move, the number becomes divisible by 3.
We are given a permutation of numbers from 1 to $n$ and a sequence of queries asking for the result of repeatedly deleting local minima and maxima from subarrays until only one element remains.
We are given an array of integers, and we need to consider every triple of indices $i < j < k$. For each triple, we take the three values, reorder them conceptually so we can identify the two smallest, and then compute the gcd of those two smallest values only.
We are given a rooted binary tree. Every node contains one character: - 'L' means "go to the left child" - 'R' means "go to the right child" - 'U' means "go to the parent" If the requested destination does not exist, the traveler stays where he is.
The original graph gives directed connections between vertices, and then we repeatedly “complete” it under a transitive rule: whenever there is a path of length two from a vertex $a to b to c$, we eventually add a direct edge $a to c$.
We are given a line of cells where each position is either usable or blocked. Only usable positions can ever hold water, while blocked ones act as permanent walls that split the line into independent regions.
The problem presents a set of digits consisting of only 1, 2, and 3. We are given counts a, b, and c for each digit, representing the number of times 1, 2, and 3 appear on the board, respectively.
Let $f(x)=a_nx^n+a_{n-1}x^{n-1}+\cdots+a_0$ with $a_n\ne 0$, and define for a natural number $k$
We are given a tree with n vertices, each labeled with an integer. The operations allowed let us remove leaf vertices (vertices with at most one edge) any number of times.
We are given a road represented as a sequence of points along the x-axis, starting at (0,0) and ending at (n-1,0). Each point has a height above the x-axis, initially given by array a.
We are asked to determine the minimum initial power $x$ of a chain lightning spell that can defeat a row of monsters no matter how the spell propagates, provided we choose the first monster to hit optimally.
We are given an array of non-negative integers. In a single operation, we can choose a number $x$ and add it to each element, then divide each element by 2, rounding down. This affects all elements simultaneously.
We are asked to simulate a chip moving along a ribbon of cells, where each cell initially contains zero. On the first turn, the chip starts at the first cell, and on every subsequent turn, we can either move it to the next cell or teleport it to any cell.
We are moving along a straight road from position 0 to position x and then returning back to 0. The car consumes fuel proportional to distance, one unit of fuel per unit of distance.
We are given a tree with n vertices, where each vertex carries an integer value. A tree is an acyclic connected graph, which ensures there is exactly one simple path between any two vertices.
We are given a list of $n$ strings, each consisting of lowercase letters. We are asked to compute the sum of lengths of all pairwise “collapsed” concatenations, where the collapse removes consecutive repeated letters at the junction of two strings.
We are given a fixed sequence of moves of a robot on an infinite grid, where each character moves the robot by one unit in one of the four cardinal directions. For every query, we conceptually modify this path by reversing a single contiguous segment of the command string.