brain
tamnd's digital brain — notes, problems, research
41650 notes
We are given a small collection of digits, and we are allowed to increase exactly one of them by one unit. After this single modification, we compute the product of all digits and want to maximize it.
We are given a $10 times 10$ grid representing a target with five concentric scoring rings. Each cell of the grid either contains an arrow, denoted by X, or is empty, denoted by ..
We are given three distinct cards labeled a, b, and c, arranged in some order. Our goal is to determine whether, using at most one swap of two cards, we can transform the row into the ordered sequence abc.
We are asked to navigate a directed acyclic graph (DAG) from vertex 1 to vertex n, collecting cards and props along the way, and then maximize our total “power” at the end. Cards have both HP and damage, and their power is the product of the two.
We are asked to count permutations of numbers from 1 to n that avoid certain ordered subarrays. More concretely, for each index l, we are given a number ml, and any contiguous segment starting at l and ending at r ≤ ml must not be a consecutive permutation of [l, l+1, ..., r].
We have a simple linear chain of cities numbered from 0 to n, connected sequentially by n roads. Each road has a "beauty" value, which determines the probability that Jellyfish will traverse it if she stands at one of its endpoints.
We are asked to analyze a variant of quicksort where the first element is always chosen as the pivot. For any array, the "time" the function takes is defined recursively as the size of the array plus the time taken by the recursive calls on elements smaller and larger than the…
We are asked to transform a pair of non-negative integers (x, y) from an initial state (a, b) to a target state (c, d) using a small set of bitwise operations. The operations available are x := x & y, x := x The constraints are significant.
We have two players, Jellyfish and Gellyfish, each with a collection of green apples. Jellyfish has n apples with values stored in array a, and Gellyfish has m apples with values stored in array b. They play a game for k rounds.
We are given a directed acyclic graph in a very specific form: every edge goes from a smaller numbered city to a larger numbered city. This means the graph is already topologically sorted by vertex index. We start at city 1 and want to reach city n.
The condition $abc=1$ suggests eliminating one variable from denominators by rewriting powers of $a,b,c$ in terms of the other two variables.
Chaneka is trying to master a challenging video game level divided into n sequential parts. She starts with some familiarity value for each part, given as an array a of size n.
We are asked to pick exactly k clownfish from a sequence of n available fish, each with a given size. Each fish can be assigned either a female or male gender at the time of selection, but the genders follow strict sequence rules.
We are given a tree where every edge is either already directed or still undirected. The task is to decide two things for the undirected edges: their directions and a color assignment for every edge. Directed edges already come with a fixed direction but still need a color.
We are given an array of integers, and our task is to assign each element one of two colors, blue or red. The goal is to count all colorings that satisfy two conditions.
We are given an array of positive integers a of length n. The task is to perform a sequence of "circle" operations on elements of a. Each operation selects an element by its index and "circles" it, and we can circle the same element multiple times.
We are asked to distribute an announcement among $n$ residents at minimum cost. Pak Chanek can notify any resident directly at cost $p$, and each resident who receives the announcement can forward it to a limited number of other residents $ai$, paying $bi$ per share.
We are given an array of integers representing values at different positions. Chaneka can select one or more indices to color black. After that, every element at a position that is a multiple of a black index turns green.
We have a round-robin football tournament with $n$ teams. Every pair of teams plays exactly one match. For each team, its efficiency is defined as: $$text{goals scored} - text{goals conceded}$$ After the tournament finishes, the efficiencies of all teams are computed.
We are given a tree where each vertex carries a small integer value. For any two vertices $u$ and $v$, we define a function that aggregates all values along the unique simple path between them using bitwise OR. This produces a single number summarizing the entire path.
We are maintaining a single integer that changes over time, and after each update we need to answer whether it is possible to “complete” it into a very specific divisor structure using an auxiliary number that shares no prime factors with the current value.
We are given an array of integers and multiple queries. Each query specifies a starting index $l$ and a threshold $k$. The task is to find the largest ending index $r ge l$ such that the bitwise AND of the subarray from $al$ to $ar$ is at least $k$.
We are given a string indexed from 1 to n, and the index range is partitioned into k consecutive segments. Each segment i covers a continuous interval from li to ri, and these segments exactly tile the entire string without gaps or overlaps. We then process a sequence of queries.
We are asked to build a strictly increasing array of length $n$, where each element is a positive integer, and $n ge 3$.
The problem asks whether, given an array of integers and a target integer $k$, there exists at least one contiguous subarray in which $k$ is the element that appears more frequently than any other element.
The problem asks whether we can pick exactly k distinct integers from the set {1, 2, ..., n} such that their sum equals x. Each test case provides three integers: n, the upper bound of the numbers we can choose; k, the number of elements we must select; and x, the target sum.
We are given several independent game configurations, each describing a set of heroes. Each hero has two parameters: health and armor. The game proceeds in discrete rounds, and in every round we choose a fixed damage value x that stays constant for the entire simulation.
We have a weightlifting competition with n athletes. Athlete i has strength si and endurance ei. A barbell weight w is chosen. Any athlete whose strength is less than w cannot lift the barbell at all. Any athlete whose strength is at least w lifts it exactly ei times.
We are given an array of non-negative integers. For every subarray $[l,r]$, we compute the XOR of all elements inside that subarray. Let that XOR value be $f(l,r)$. The contribution of a subarray is not just its XOR.
We are given a rooted tree with $n$ vertices, where vertex 1 is the root. Each vertex $i 1$ has a parent $pi$, so the tree is naturally defined by this parent array.
We are given a binary string, and we are allowed to delete characters from arbitrary positions. After deleting some characters, we want the remaining string to be alternating, meaning no two adjacent characters are equal.
We are given an $n times n$ grid and two arrays $a$ and $b$, each of length $n$. We want to place chips on some cells so that every cell shares a row or column with at least one chip. Placing a chip on cell $(i, j)$ costs $ai + bj$.
We are given a string that is continuously modified and queried. Each modification shifts all characters in a segment forward in the alphabet cyclically, like a Caesar shift applied to a range. After each update, we must answer whether a chosen substring is “valid”.
We are given a tree and a subset of its vertices marked as special. For every vertex $v$, define $f(v)$ as the distance from $v$ to the farthest marked vertex. We want to choose a vertex whose farthest marked vertex is as close as possible.
We are given a sequence of integers, and our goal is to transform it into a "beautiful" sequence using the minimum number of deletions.
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 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 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 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 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 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 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.