brain
tamnd's digital brain — notes, problems, research
41650 notes
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.
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.