brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to turn a sequence of numbers into all zeros using a particular operation. In each operation, we pick two distinct elements. If they are equal, we replace one of them with zero. If they are different, we replace both with the smaller of the two.
We are given a binary string and allowed to flip any individual character at unit cost. After all changes, the string is interpreted by compressing it into maximal runs of identical characters.
We are given a length $n$ string of decimal digits, and a set of constraints between digits in the form of allowed adjacent swaps.
We are given a string of length n composed of the first 17 lowercase letters (a through q) and question marks. Each question mark acts as a wildcard that can be replaced by a letter from a specific set provided in a query.
The problem gives a directed graph where each vertex has a positive integer value. Masha can place a coin on any vertex, and then move it along the graph edges exactly $k-1$ times. Every time the coin visits a vertex, the vertex’s number is recorded in a notebook.
We are asked to determine how many buses a fleet could have given the total number of wheels. Each bus comes in one of two types: two-axle buses with 4 wheels and three-axle buses with 6 wheels.
We are given an array of integers and a sequence of queries. Each query either replaces a single element in the array with a new value or replaces every element in the array with the same value. After each query, we need to report the sum of the array.
We are asked to simulate a sequence of operations on an $n times n$ chessboard involving rooks. Each rook attacks its entire row and column.
We are asked to construct arrays called beautiful arrays. A beautiful array is one in which the number of elements equal to the minimum value falls between two given bounds, $l1$ and $r1$, and the number of elements equal to the maximum value falls between two bounds, $l2$ and…
We are asked to find a lenient vertex cover for a connected undirected graph. A normal vertex cover is a set of vertices such that every edge touches at least one vertex in the set.
We are given a sequence of movements of a dog along an infinite line. Each minute, the dog moves a certain distance. Positive numbers move it to the right, negative to the left, and zero indicates unknown movement where we can pick any integer in the range $[-k, k]$.
We are given a $2 times n$ board where some cells contain chips, represented by '', and others are empty, represented by '.'. Our task is to move chips so that exactly one chip remains on the board.
We are given a small rectangular grid, with each cell either empty or containing a robot. Robots can move simultaneously in one of four cardinal directions, and if any robot tries to leave the grid, it explodes.
We are given a binary string and we are allowed to cut it in a very specific way: we choose some prefix and suffix to remove, leaving a single contiguous substring in the middle. The remaining substring is what we “keep”, while everything outside it is considered removed.
Two players each hold a multiset of integers. They play a turn-based game where the only rule is that every newly played number must be strictly larger than the previous one.
We are given a tree with $n$ vertices. Each edge has an integer label. For any pair of vertices $v$ and $u$, we define $f(v, u)$ as the number of edge labels that appear exactly once along the unique path connecting $v$ and $u$.
We are given a labyrinth structured as concentric layers in an $n times n$ grid. Each layer is a contiguous set of cells surrounding the previous layer. The first layer is just the bottom-left corner.
We are given an integer x and a target length n. We can repeatedly choose any digit y from the current number x and multiply x by y. The goal is to make x have exactly n digits using the minimum number of such operations.
We are given two arrays of the same length, a and b. We can perform a special swap operation: choose any two positions i and j, and simultaneously swap a[i] with a[j] and b[i] with b[j].
We are given a deck of n cards with distinct integer values, ordered from top to bottom. We then perform m shuffle operations, each defined by a number bj.
We are asked to construct a tree on n nodes arranged in a circle. Each node has a requirement: its degree must be even or odd, depending on the corresponding character in a binary string s.
We are given a sorted array a and an integer array b. Each query gives a segment [l, r], and we only care about it if the sum of b over this segment is zero. This condition guarantees that total “supply” and “demand” inside the segment balance perfectly.
We are given a permutation of integers from $1$ to $n$ and a set of $m$ swaps, which are guaranteed to be the minimum swaps required to sort the permutation. These swaps have been shuffled arbitrarily.
We are given a permutation of the integers from 0 to n−1, and we are allowed to rearrange it using a very unusual swap rule. A swap between two positions is only allowed when the bitwise AND of the two values currently stored at those positions equals a chosen value X.
We are given a string that is already a palindrome, meaning it reads the same from left to right and right to left. For each position in this string, we imagine removing exactly one character and then ask whether the remaining string is still a palindrome.
We are given several test cases. Each test case provides a multiset of numbers, and we are allowed to rearrange them in any order we want. After choosing an ordering, we look at two sequences: the chosen array itself, and its reverse.
We are given a binary string, which is a sequence of '0's and '1's. Our task is to partition this string into contiguous substrings in such a way that, if we interpret each substring as a binary number and sum them all, the result is a power of two.
We are given a multiset of positive integers, and we are told that this multiset was produced by repeatedly running Euclid’s algorithm on several unknown integer pairs.
We are given a sequence of traps, each with a base damage value. We traverse the traps in order, and for each trap we either take its damage or skip it by jumping over it.
We are given an array and several queries, where each query describes a segment of indices. The requirement is that inside every given query segment, all values must be pairwise distinct. If the array already satisfies this condition for all segments, we do nothing.
We are given an array of non-negative integers and we are allowed to perform up to k replacements, where each replacement changes any element to any non-negative value. After these edits, we evaluate the array using two quantities.
We are asked to construct three positive integers $x, y, z$ given three constraints on remainders. Each constraint relates one number to another through a modulo operation: the remainder when dividing $x$ by $y$ must equal $a$, the remainder when dividing $y$ by $z$ must equal…
We are given a matrix where each row represents a sequence of numbers arranged across columns. The goal is to make every row individually non-decreasing from left to right, but we are only allowed a single global operation: swap two entire columns.
We are given an integer with no zero digits, and two players, Alice and Bob, play a turn-based game on its digits. Alice always moves first and can swap any two digits at different positions. Bob always removes the last digit of the number.
We are asked to transform one permutation into another in a way that minimizes a specific “weight” function. The weight is the sum of absolute differences between each element of the new permutation and the element of the original permutation located at the next position in…
We are given a permutation of size $2n+1$, and this array keeps changing through swaps of two positions. After every swap, we are not asked to analyze the array itself directly, but to consider all its cyclic rotations and determine whether at least one rotation has a…
We are given a permutation p of the numbers from 1 to n, and our task is to construct another permutation q of the same numbers that minimizes a specific weight function.
We are asked to arrange a set of integers on a circle so that each number is either strictly larger or strictly smaller than both of its neighbors. The input consists of multiple test cases. Each test case provides the number of integers, followed by the integers themselves.
The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.
We are given a sequence of parentheses of length $2n$, containing exactly $n$ opening and $n$ closing brackets. The task is to transform this sequence into a correct balanced parentheses string using the minimum number of operations, where each operation consists of reversing…
We are given a permutation of the numbers from 1 to n. We may split this permutation into any number of consecutive pieces. Each piece is a subarray. For every subarray, we look at its inversion count. A subarray is called odd if its inversion count is odd.
We are given several independent test cases. Each test case starts with an array of integers. The only operation allowed transforms the array in a very specific way: we pick exactly one element to leave untouched and replace every other element by the average of the chosen group.
The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.
For every integer, look at the two consecutive perfect squares surrounding it. If $$m^2 le x < (m+1)^2,$$ then $g(x)=m^2$ and $f(x)=(m+1)^2$. The number is called cute when it is strictly closer to the lower square than to the upper square.
We are given a sequence of integers a and a number v initialized to 1. The task is to perform a series of operations on v so that it becomes the greatest common divisor of all pairwise products of elements from a.
The solution addresses the exercise directly. It identifies the event $f(n)-f(n-1) = k$ as the occurrence of exactly $k-1$ consecutive terms outside the interval $[alpha,beta)$ followed by one term inside, which correctly models the "gap" between hits in the interval.
We are asked to compute the maximum number of mushrooms Marisa can collect in a one-dimensional forest over a limited number of minutes.
We are given a railway network consisting of n stations and m bidirectional tracks, each with a positive length. The network may not be fully connected and can have multiple tracks between the same pair of stations.
We are asked to reconstruct the initial string of length 1 from which a sequence of operations produced a given final string. Each operation consists of selecting a substring of the current string and replacing it with another string, possibly of different length.
We are given a positive integer $x$, and the task is to find the smallest positive integer $y$ such that two bitwise conditions hold simultaneously: the bitwise AND of $x$ and $y$ is greater than zero, and the bitwise XOR of $x$ and $y$ is also greater than zero.
We are asked to transform a collection of magical tokens so that every token has an odd magical power. Each token starts with some positive integer power.
We are given a permutation $p$ of the numbers $1$ through $n$. We want to construct another permutation $q$ using the same numbers such that every position changes. For every index $i$, the value placed in $qi$ must be different from $pi$.
We are given an array of non-negative integers. Each array element corresponds to a vertex in a graph. Two vertices are connected by an edge whenever the bitwise AND of their values is positive. The graph is not guaranteed to be connected.
We are given a grid of size $n times m$, where each cell is either black or white. Our task is to pick a cell such that the maximum Manhattan distance from this cell to any black cell is minimized.
We are given a binary tree rooted at vertex 1. Each vertex has at most three neighbors, except the root which has at most two. Initially, only the root is infected.
We are given two strings, a and b, which do not share any letters. We can build a new string c by repeatedly taking the smallest available letter from either a or b. However, there is a restriction: we cannot take more than k characters from the same string consecutively.
Each carriage has its own maximum speed. When all carriages start moving, a carriage cannot move faster than any carriage in front of it, so its actual speed becomes the minimum value seen so far from the left.
We are given two increasing arrays. The array s contains the arrival time of each task. Task i becomes available at time s[i]. The array f contains the completion time of each task. Task i finishes exactly at time f[i]. Polycarp processes tasks in FIFO order.
We are given a string s of length n and a permutation p of the integers from 1 to n. Each permutation p defines a reordering operation: after one application, the character at position i in the new string moves to position p[i].
We are given an even number of goods, each with a weight, and we need to pack them into pairs. The cost of a pair is calculated by taking the sum of its weights, dividing by a fixed number $k$, and rounding down to the nearest integer.
We are given a stripe of tiles, each either white or black, and the goal is to ensure that at least one segment of exactly k consecutive tiles is entirely black.
We are given two arrays of non-negative integers, a and b, both of length n. The allowed operation is to simultaneously decrement all positive elements of a by one.
We are given a number of identical building blocks and must split them into three stacks representing a podium. Each stack corresponds to a rank: third place, second place, and first place.
We are given a binary string of length $n$ and we want to minimize a sum computed from all consecutive pairs of digits. Each pair of digits $si s{i+1}$ is treated as a decimal number, so "10" counts as ten, "01" as one, and so on.
We are given an undirected tree with $n$ vertices. For every choice of a root $r$, the tree becomes rooted. For every $k$-element vertex set $S$, we look at the smallest rooted subtree that contains all vertices of $S$. A rooted subtree is not just any connected subgraph.
We are given a set of segments on the number line, each colored either red or blue. Each segment occupies a continuous interval from li to ri, inclusive.
We are asked to determine whether, for a given integer array, the maximum value in any contiguous subarray is at least as large as the sum of that subarray.
We are given a sorted list of shoe sizes for a group of students. Each student initially owns exactly one pair of shoes, and we want to redistribute these shoes among the students so that everyone receives exactly one pair.
We are given a sequence of integers, and we need to remove as few numbers as possible so that every pair of consecutive numbers in the remaining sequence sums to an even number. The sum of two numbers is even if both numbers are even or both are odd.
We know the outcomes of the next $n$ dice rolls in advance. Marian chooses a value $a$, and a contiguous segment of rounds $[l,r]$. During every round in that segment he always guesses the same value $a$. Whenever the actual rolled value equals $a$, his money doubles.
We are given an array and asked to examine every contiguous segment of fixed length $k+1$. For each such segment starting at position $i$, we conceptually transform it by multiplying element $j$ (relative to the segment start) by $2^j$.
We are given a starting time on a 24-hour clock and a fixed number of minutes between observations. Starting from the given time, Victor repeatedly looks at the clock after every $x$ minutes.
We are given an array of positive integers, and we want to know if we can select three distinct elements whose sum ends with the digit 3. In other words, if we denote the chosen elements as $ai$, $aj$, and $ak$, then $(ai + aj + ak) mod 10 = 3$.
We are given a binary array of length $n$, meaning each element is either 0 or 1. The task is to perform a sequence of operations where, in each operation, we remove either the first or the last element of the array.
We are given an array of integers. In one operation, we must remove exactly two elements from the array. The two removed elements can be any values, as long as they come from different positions.
We are asked to determine Timur's position relative to three other runners in a marathon. Each test case provides four distinct integers: Timur's distance first, followed by the distances run by three other participants.
The discrepancy is not caused by a small implementation bug. The outputs show that the algorithm itself is overcounting the cost of independent intervals.
The problem gives a binary string consisting of 0s and 1s, and you are allowed to perform a sorting operation on any contiguous substring.
We are given an array of length $n+2$, where the first and last elements are fixed at zero, and the middle $n$ elements are arbitrary non-negative integers.
We are given a permutation of numbers from 1 to $n$, and we are asked to count the number of contiguous subarrays that are "Decinc." A subarray is Decinc if we can remove some decreasing subsequence (possibly empty) so that the remaining elements are strictly increasing.
The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.
We are given a rooted tree. Every vertex starts with value 0, and each vertex v has a required interval [lv, rv]. An operation chooses some root-to-vertex path and adds values along that path.
We are given a directed graph representing cities in Italy connected by roads. Keshi starts in city 1 and wants to reach city n, where AmShZ is waiting. Each day, AmShZ can either mark a single road as blocked or instruct Keshi to move.
The proposed solution answers the exercise that was actually asked. Exercise 3.4.2.10 asks for a modification of Algorithm R that eliminates the reservoir when the current sample of size $n$ can be stored directly in memory.
We are asked to count substrings of a binary string that are "paranoid." A paranoid string is one that can be reduced to a single character by repeatedly applying two operations: replacing 01 with 1 or 10 with 0.
I can't reliably produce a complete, correct editorial and accepted implementation for Codeforces 1695E from memory alone.
We are asked to determine the minimum number of distance queries required to uniquely identify a hidden vertex in a tree. The input gives us a series of trees, each defined by its vertices and edges.
We are given an unrooted tree with $n$ vertices. There is a hidden vertex $x$ that we need to identify. The only operation we can perform is a query where we select some vertices and, for each, we receive the distance to the hidden vertex.
We have a grid whose cells contain only 1 or -1. Starting at the upper-left corner, we may move only right or down until we reach the lower-right corner. Every visited cell contributes its value to the path sum. The task is not to find the number of such paths or the minimum sum.
We are given a grid containing distinct integers. Michael chooses dimensions h × w, then Joe secretly selects any subrectangle of exactly that size. Michael must name the maximum value inside Joe's chosen rectangle before seeing which rectangle was selected.
We are asked to analyze a two-player game played on a circle of stone piles. Each pile has a certain number of stones. Players take turns removing a positive number of stones from the current pile.
We are given a collection of integers where each element is tied to its index, so even equal values are treated as distinct items. From this collection, every subset is considered independently.
We are given two arrays and a fixed integer $m$. Starting from the first array, we may repeatedly split an element divisible by $m$ into $m$ equal pieces, or merge $m$ consecutive equal elements into one larger element.
We are given an array whose values represent amounts that must be removed. An operation acts on one adjacent pair. If we spend $t$ seconds on edge $(i,i+1)$, we may subtract $(x t, y t)$ from the pair or $(y t, x t)$ from the pair.
We are asked to reconstruct a tree based on a set of distance equalities between triples of vertices. Formally, for each pair of vertices $x$ and $y$, and for each vertex $z$, we know whether $d(x, z) = d(y, z)$ or not.
We are given a permutation of integers from 1 to n and asked to construct a graph based on the relative minimum and maximum values in contiguous segments.
We are asked to control dolls on an infinite grid where each cell can be white or black. The color of each cell is defined by a non-increasing sequence $a0, a1, dots, an$, extended with zeros beyond $n$.
We are given an array representing the “universe,” where each element is a non-negative integer. The protagonist, NIT, can perform a specific operation on any contiguous subarray: compute the mex of that subarray and set every element in it to that mex.
We are given an array of integers and a number $z$. We are allowed to repeatedly pick any element $ai$ and perform two bitwise operations: update $ai$ to $ai operatorname{or} z$ and simultaneously update $z$ to $ai operatorname{and} z$.
The problem gives two strings s and t of the same length consisting of the characters 'a', 'b', and 'c'. The allowed operations let us swap adjacent "ab" to "ba" and "bc" to "cb". The task is to determine whether we can transform s into t using any number of these moves.