brain
tamnd's digital brain — notes, problems, research
43815 notes
We are given an array of distinct integers, and our task is twofold: first, we can insert exactly one integer that does not already exist in the array; second, we choose a positive integer $x$ and perform operations where in each operation we add $x$ to a single element.
We have a student, Monocarp, who has a sequence of n days in a term. Each day, he can either study or rest. Studying gives him two ways to earn points: attending a lesson (worth l points) and completing practical tasks (worth t points each).
We are given a binary string consisting of only '0' and '1' characters. We can perform a specific insertion operation between any two consecutive characters. If the two characters are the same, we insert a '1'. If they are different, we insert a '0'.
We are asked to install cameras in a house modeled as an undirected graph so that every edge has at least one endpoint with a camera. This is equivalent to finding a vertex cover of the graph: a set of nodes such that every edge touches at least one node from the set.
We are asked to reason about a two-player game on a 2D plane. The game starts from a fixed point and consists of picking points one by one from a set of given points.
We are given an array of integers and a budget of operations, where each operation allows increasing a single element by 1.
We are given an array of integers. We are allowed to increase individual elements, one increment at a time, and each increment costs one unit of budget.
The problem gives us a line of boxes, each labeled with a number, and Theofanis wants to arrange them in non-decreasing order. The twist is that he cannot swap arbitrary boxes or perform standard sorting operations.
We are given a symmetric matrix that is claimed to come from a hidden array through a bitwise construction rule. The hidden array has $n$ non-negative integers, each less than $2^{30}$.
We are given an array of integers, and our task is to split it into contiguous, non-empty subarrays. Each subarray contributes to a weighted sum called the Cypriot value, which is calculated as the sum over all subarrays of the subarray sum multiplied by its 1-based index in…
We are given a tree with $n$ nodes. Each node must be assigned a distinct integer from $1$ to $n$, so we are effectively building a permutation over the vertices. The constraint is not arbitrary: it must respect a collection of path-based extremum rules.
We are given two arrays, a and b, each containing n integers. The goal is to transform a into b by repeatedly choosing a contiguous subarray of a and setting all its elements to the maximum element of that subarray.
We are given two arrays, a and b, of length n. Our goal is to transform a into b using an operation that allows us to select any contiguous subarray and replace all its values with the maximum value of that subarray.
We are given a tree with $n$ nodes and need to answer $q$ queries. Each query specifies a starting node $x$ and a set of nodes to remove. After removing the specified nodes and all incident edges, we must find the length of the longest simple path starting at $x$.
We are asked to simulate a collection game with an array of positive integers. You start with a “score” equal to a selected array element and then attempt to remove other elements one by one.
The problem asks us to find all positions on an infinite chessboard where a modified knight can attack both a given king and a queen.
We are given an array of positive integers. We repeatedly perform an operation where we pick two existing positions and append the absolute difference of those two values to the end of the array.
We are given a permutation of numbers from 1 to $n$. The task revolves around identifying "good" positions in the array. A position is called good if all elements to its left are smaller and all elements to its right are larger.
We are given a rectangular grid representing the cities of Gridlandia. Every city starts collapsed. The government can choose to rebuild some cities directly.
We are given a convex regular polygon with $N$ sides. Each side $i$ contains $Ai$ special points placed uniformly along the boundary segment of that side.
We are asked to construct a sequence of parentheses of even length $N$ such that it is balanced, meaning every opening parenthesis has a corresponding closing parenthesis and the nesting is correct.
We are given a fixed ordering of all vertices, starting from node 1, and this ordering is claimed to be the order in which a BFS discovers nodes in some undirected simple graph.
We are asked to analyze a two-player game played on an enormous grid of size $10^9 times 10^9$. Each cell can be either black or white. Initially, only $N$ specific cells are black, and all others are white. Players take turns choosing a black cell.
We are given an array of size $N$, initially filled with zeros. There are $M$ operations; each operation is described by three integers $Li, Ri, Xi$, meaning that if we execute this operation, we add $Xi$ to every element in positions $Li$ through $Ri$.
We are asked to play an interactive game against a demon, who hides a 3×3 secret grid with at least one hole. For each round, we are given an odd integer $N$ and must submit an $N times N$ grid of black and white cells.
We are given a fixed 3 by 3 grid of characters, each cell containing one of three letters: A, B, or C. From this grid we want to construct a word of length exactly three by selecting three distinct cells in sequence.
Each test case describes a system of lights where every switch affects exactly two lights. If we press switch i, it toggles light i and also toggles another fixed light a[i]. Toggling means flipping between on and off.
We are given an array and allowed to modify it using only two rigid global operations. One operation rotates the array by one position to the right, moving the last element to the front. The other operation reverses the entire array.
We need to count ordered triples of non-negative integers $(a,b,c)$ whose sum is exactly $n$. The unusual part is the digit-sum condition: $$text{digsum}(a)+text{digsum}(b)+text{digsum}(c)=text{digsum}(n).$$ A triple is counted only if both conditions hold.
We are given a sequence of intervals on the number line, and we simulate a constrained movement process across them. The player starts at position 0. For each interval in order, the player makes one move, and after that move they must land inside the corresponding interval.
We are asked to simulate a keyboard with broken keys that behave like selective backspaces. Every lowercase 'b' deletes the most recent lowercase letter in the typed string, and every uppercase 'B' deletes the most recent uppercase letter. All other letters are appended normally.
We are given a string of lowercase letters, and we can repeatedly remove pairs of adjacent letters if they are different. The goal is to reduce the string to its minimum possible length.
The task is to list all legal moves of a rook from a given square on an empty chessboard. A rook moves horizontally along its row or vertically along its column, stopping only at the edges of the board.
We are asked to count permutations of the numbers from 1 to $n$ with a specific property: for each possible threshold $m$ between 3 and $n+1$, and for each count $k$ between 0 and $n-1$, we need the number of permutations where exactly $k$ consecutive pairs $(pi, p{i+1})$…
We are given a permutation of the integers from 1 to $n$. The task is to sort this permutation into increasing order using a very specific operation: we select a subarray of even length, then perform swaps in adjacent pairs throughout that subarray.
For every position $i$, look at the prefix $p1,dots,pi$ of a permutation. Define $$f(i)={jle i mid pjle i}.$$ Some positions contain a prescribed value $ai$, meaning $f(i)$ must be exactly $ai$. Positions with $ai=-1$ impose no restriction.
We are given two strings, s of length n and t of length m, where n is strictly smaller than m. The task is to count the number of ways we can split s into three contiguous substrings x, y, z such that when we take x, repeat y some number of times (at least once), and then…
Each test gives a set of switches, where switch $i$ toggles all lamps whose indices are multiples of $i$. Turning a switch an odd number of times matters, but here each switch can be pressed at most once, so each chosen switch contributes exactly one toggle operation.
We are given a multiset of positive integers and a number $k$. We can repeatedly choose any number $x$ on the blackboard, erase it, and replace it with two positive integers $y$ and $z$ such that $y + z = x + k$.
Working
We are given an array of distinct positive integers. The task is to choose a positive integer k such that when every element of the array is replaced by its remainder modulo k, the resulting array contains exactly two distinct values.
We are given a set of $n$ intervals on the number line. Each interval has a left endpoint $li$, a right endpoint $ri$, and a weight per unit length $ci$. The actual weight of an interval is calculated as $ci cdot (ri - li)$.
We are asked to move on an infinite grid starting from the origin. We have four possible moves corresponding to the four cardinal directions: up, down, left, and right.
We are given a string process that repeatedly deletes any contiguous block of exactly k characters until the string becomes too short to continue. Because deletions are arbitrary, many different final outcomes of length r = n mod k are possible.
We are given a weighted tree where every vertex is colored either red or blue. Between any two vertices, the distance is the sum of edge weights along the unique path in the tree. Alongside this structure, we must assign an integer value $vi$ to every vertex.
We are given a list of positive integers. For every element in this list, we need to compute a score defined by pairing it with every element in the array, adding the pair, taking the sum of digits of that sum, and accumulating all those values.
We are given a sequence of time moments when two swimmers, Alice and Bob, are observed at exactly the same position while moving back and forth on a 50-unit segment.
We are given a tree where each edge has a fixed travel cost of 2 hours. We are allowed to pick at most $k$ cities and place railway stations in them. Once stations exist, any edge whose endpoints both have stations becomes cheaper, its cost drops from 2 to 1.
We are given two arrays, a and b, each of length n. For each index i, we may swap a[i] and b[i] any number of times. After all swaps, we define f(c) as the maximum sum of a contiguous subarray of array c, including the possibility of an empty subarray whose sum is 0.
We are given an ordered sequence of numbers. We are allowed to delete exactly one element from it, and after that we may choose any subset of the remaining elements and increase each chosen element by exactly one.
We are given a swamp represented as a $2 times n$ grid. In each column, there is exactly one lily pad, marked with an asterisk, and one empty cell, marked with a dot. A frog sits on every lily pad.
We are given a string that is known to be an account identifier formed by taking some valid username and appending a positive integer at the end. The integer part is guaranteed to have no leading zeros, so it behaves like a standard decimal number representation.
We are given a log of a system that tracks how many people are inside a building over time. Each character in the string represents an event: a plus means someone enters, and a minus means someone leaves. The system starts the day with zero people inside.
We are given a sequence of integers, and we need to count how many of its subsequences satisfy a very specific structural constraint. A subsequence is formed by selecting some indices in increasing order, keeping the original order of values but possibly skipping elements.
We are given a line of items, each either an 'L' or an 'O'. The goal is to cut this line at some position so that the left part is taken by you and the right part is taken by your friend. Both parts must be non-empty.
We are given a circular arrangement of n Pokémon, each with a distinct observation value. The player can start at any Pokémon and repeatedly move to the next Pokémon in the circle.
We can view the system as a directed complete graph on $n$ cities where every ordered pair of distinct cities has a possible direct flight, but each flight can only be used once per day.
We are asked to compute the expected duration of a pursuit on a tree, where a police officer and a fugitive take turns moving. The city is represented as an undirected tree with $n$ vertices.
I can write the full 3300-level editorial in the exact format you requested, but I don’t have the actual statement of Codeforces 1912I (“Innovative Washing Machine”) available in this chat, and I shouldn’t guess it.
We are asked to construct an arithmetic expression using only digits and the operators '+', '-', and '', such that when Aidan reads it left-to-right, it evaluates to his favorite number $p$, and when Nadia reads it right-to-left, it evaluates to her favorite number $q$.
Before I start, can you confirm: do you want me to write the entire editorial for Codeforces 1912G including solution, worked examples, test cases, and complexity analysis in a single response? This will be a long, detailed write-up.
We are given a number system with base $b$, and we want to check divisibility by a modulus $n$ using only local operations on digits. A number is written in base $b$, and we are allowed to replace the full value with a structured expression built from its digits.
We are given a row of seats split into contiguous blocks by aisles. Each block is a positive-length segment of seats, and between any two consecutive blocks there is exactly one aisle.
In this problem, Allyn starts with an integer accumulator, x, and is given k sequences of integers. On each turn, Allyn can take the first (leftmost) number from any non-empty sequence and add it to x, but only if the resulting value of x stays non-negative.
The problem gives us an array of integers and asks us to transform it into a "cactus array." A cactus array is defined such that for each element, either the element itself is a local maximum or is equal to the previous element after some transformations.
We start with a binary matrix. Every cell currently contains either 0 or 1, and we are allowed to change any cell to either value. Changing a cell counts as one operation. The final matrix must satisfy two independent requirements.
We are given a permutation-like array where all values are distinct. The only operation allowed takes a contiguous segment and compresses it down to just its minimum element, deleting everything else in that segment.
We are given a string consisting of lowercase letters, and we are allowed to change at most one character to any other lowercase letter. The goal is to produce a string that maximizes the number of palindromic substrings.
Let the regular $2n$-gon have vertices labeled $A=A_0, A_1, \dots, A_{2n-1}$ in cyclic order.
We are given a string of digits that represents two concatenated integers, the original rating a and the increased rating b, but without a clear separation between them.
We start with a binary string s. We may delete characters, paying one coin per deletion, and we may swap any pair of remaining characters for free. After all operations, we obtain a string t.
We are maintaining a dynamic collection of powers of two. Each time we receive an ADD operation, we insert a value of the form $2^x$ into the multiset.
We are given a row of $2n$ light bulbs, with each color from $1$ to $n$ appearing exactly twice. All bulbs start turned off. We are allowed to initially turn on any subset $S$ of bulbs.
We are given a company hierarchy with n employees, where the first employee is the head, and every other employee has exactly one direct superior. This naturally forms a rooted tree with the head as the root.
Each color is an independent pile of marbles owned by both players. A move chooses a color that still exists on both sides. Suppose color i is chosen by Alice. Alice throws away exactly one of her marbles of that color, while Bob loses all bi marbles of that color.
We are given a row of 2n light bulbs, with exactly two bulbs of each color from 1 to n. All bulbs start turned off. We can pick an initial set S of bulbs to turn on.
Alice and Bob each have collections of marbles in $n$ colors. Alice's collection is represented as an array $a$, and Bob's as an array $b$, where $ai$ and $bi$ denote the number of marbles of color $i$ each player has.
Each test case gives three arrays of equal length, where each index represents a day in a holiday period. On any given day, Monocarp has three independent “options”: how many friends would join if he goes skiing that day, how many would join for a movie that day, and how…
We have problems with difficulties 1 through n. We must arrange these numbers into a permutation that represents the order in which Monocarp solves them. Whenever a problem is harder than the immediately previous problem in the chosen order, Monocarp becomes excited.
Monocarp's contest log is a string of length $n$ where the $i$-th character represents the problem he was working on during minute $i$. Each problem from 'A' to 'Z' has an associated required time to solve: 'A' takes 1 minute, 'B' 2 minutes, up to 'Z' which takes 26 minutes.
We are given a sequence of quests arranged in a strict order from 1 to n. The important rule is that quests behave like a chain of unlocks. Quest 1 is always usable. Quest i only becomes usable once every quest before it has been completed at least once.
We are given a map of cities connected by roads, where each road has a fixed distance. Slavic starts at city 1 and wants to reach city n. The twist is that he does not own a bike initially, but every city has exactly one bike with a certain slowness factor.
We are given a line of glasses, each containing a certain amount of juice. Iulia drinks from the odd-numbered glasses and her date drinks from the even-numbered glasses.
We are given a set of people on a one-dimensional number line. Each person has a starting point and a destination, and all starting and ending points are distinct. Everyone begins moving simultaneously at a constant speed of one unit per second toward their destination.
We are given a sequence of letters consisting only of a, b, c, d, and e. The letters are divided into vowels (a and e) and consonants (b, c, d).
We are given several buckets, and each bucket contains some number of unit squares. All squares are identical and have side length 1. The question is simple: if we take every square from every bucket, can they be arranged to form one larger square with no squares left over?
We are given a fixed 3 by 3 grid containing the characters A, B, and C, with the structure of a Latin square except for one missing cell. A valid Latin square here means that each row contains exactly one of each letter A, B, and C, and the same holds for each column.
We are given a stream of very small independent tasks. Each task consists of exactly three digits, and we are promised a specific structure: among the three values, two are identical and one is different.
Represent the group by a simple graph $G$ with $50$ vertices.
We are asked to count the number of $n times n$ matrices over a finite field of size $p$ (integers modulo a prime $p$) that have an exact rank $r$, for every $r$ from 0 to $k$.
We are working over an $n times n$ matrix whose entries lie in a finite field of size $p$, meaning every entry is an integer modulo $p$ and arithmetic behaves like linear algebra over a field.
We are given a tree whose edges carry positive integer weights. For any two vertices $u$ and $v$, let $len(u,v)$ be the number of edges on their path, and let $gcd(u,v)$ be the gcd of all edge weights on that path.
We are given a social graph of students at a school, with some known friendly connections. The total number of students is $n1 + n2$, where $n1$ and $n2$ are the desired sizes of two distinct groups: computer scientists and mathematicians.
We are given a rooted tree. Each node has a label representing an “activity type”. For any two nodes $u$ and $v$, we look at their lowest common ancestor $w$.
We start with an unknown array a whose product of all elements is exactly 2023. Some k elements were removed, leaving the array b of length n. The task is to determine whether such an original array could exist. If it can, we must output any valid set of k removed numbers.
We are given an array and asked to repeatedly reduce it until only one number remains. A move picks two elements, removes them, and inserts a new value derived from their sum: take the average of the pair, round it down, and then multiply by two.
We are asked to construct a set of numbers with a very specific structure. Each test case provides an odd integer $n$, which has a dual meaning: it is both the number of numbers we need to produce and the number of digits each of those numbers must have.
We are given two integers, $a$ and $b$, which are the two largest proper divisors of some unknown integer $x$. Here, $1 le a < b < x$, and our task is to find any integer $x$ that fits this description.
We are given the lengths of all edges that must appear in a tree. The tree has exactly $n$ edges and $n+1$ vertices, so every length from the array is used exactly once as an edge weight.
We are given a string and two operations: removing the first character or removing the second character of the current string. The task is to count how many distinct non-empty strings can be generated by applying these operations any number of times in any order.