brain
tamnd's digital brain — notes, problems, research
41650 notes
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.
We are given a hidden permutation of integers from 1 to $n$. The permutation is unknown, and our goal is to determine it.
The previous attempts failed for two reasons. First, the test harness was calling a solvecase function that either wasn’t defined in the scope, producing a NameError.
We are asked to construct an array of length $n$ containing non-zero integers such that if we replace each element by the sum of its neighbors, the resulting array is a permutation of the original array. For the endpoints, the "neighbor sum" is just the single adjacent element.
We are given an array of positive integers. Our goal is to "block" some elements in order to minimize a certain cost.
The problem asks us to minimize the absolute difference between two numbers after each has been XOR-ed with a single number $x$ that we are allowed to choose.
We are given two permutations a and b of the same length. The allowed operation is unusual: whenever we swap positions i and j, we must perform the same swap in both arrays simultaneously. This means we can never separate a[k] from b[k].
We are building a full $n times m$ rectangular grid using long thin bricks, where each brick is a $1 times k$ strip with $k ge 2$. Each brick must lie entirely either horizontally or vertically, and every cell of the grid must belong to exactly one brick.
Because every valve capacity is fixed at $10^{18}$, the valves never become a bottleneck. Any water that remains in tower $i$ after the wizard acts can always move completely into tower $i+1$. This changes the nature of the process dramatically.
We are asked to reconstruct an unknown tree with $n$ vertices and $n-1$ edges by interacting with a grader that allows two types of queries. The first query lets us assign arbitrary positive weights to the edges and returns the resulting diameter of the weighted tree.
Let the squares in the sequence be
We are asked to reverse-engineer a hidden array of size $n$ that contains only $1$ and $-1$. Instead of being given the array itself, we are given the sorted list of prefix sums of the array. The prefix sum at position $i$ is the sum of the first $i$ elements of the array.
We are asked to reconstruct a tree from a matrix of game outcomes. Each entry s[i][j] indicates whether the first player can force a win when the tree is rooted at vertex i and the coin starts at vertex j. A vertex can only move the coin to its children.
We are tasked with simulating a sequence of water towers, each containing an initial amount of water. In front of each tower stands a wizard who can convert a limited number of liters into wine.
We are given an array and we must split it into two subsequences, call them $s$ and $t$, covering every element exactly once while preserving relative order inside each subsequence.
We are given the distances from the root to the leaves of a binary tree, listed in DFS leaf order. Every internal vertex has exactly two children. One outgoing edge has weight 0 and the other has weight 1.
Alice and Bob each start with a wallet containing some number of coins. On every turn, the current player may either keep the wallets as they are or swap the two wallets. After that choice, they must remove exactly one coin from the wallet they currently hold.
The string consists only of '+' and '-'. We can interpret each character as a number: '+' becomes +1, and '-' becomes -1. We are allowed to split this sequence into any number of contiguous non-empty pieces.
We are asked to count the number of binary strings such that the total number of substrings containing exactly one 1 equals a given number n, and no such substring has length exceeding a given maximum k. A substring is simply a consecutive portion of the string.
We are given a rectangular grid where some cells are islands, some are open ocean, and some are underwater volcanoes. Thomas wants to sail in loops that fully encircle the island without stepping onto it.
We are given a 2D grid representing an island in the ocean. Each cell can be part of the island (), open ocean (.), or an underwater volcano (v). The island cells form a single contiguous shape not touching the grid edges.
We start with an empty sequence and gradually build a very large array using two kinds of operations. The first operation appends a single value to the end, effectively extending the sequence by one element.
We are asked to determine how many integers satisfy a set of constraints. Each test case consists of multiple constraints on a single integer $k$. The constraints fall into three categories: $k$ must be at least $x$, $k$ must be at most $x$, and $k$ must not equal $x$.
We are asked to simulate a two-step game played on an array of positive integers. The first player, Alice, can remove up to $k$ elements. She wants the final sum of the array to be as large as possible.
Consider sequences $(a_1, a_2, a_3, \dots)$ satisfying the recurrence $a_k = a_{k-1} - a_{k-2}$ for $k \ge 3$, with terms chosen from the set $1, \frac12, \frac13, \dots$.
This is a Type B problem, a proof of existence. The requirement is to show that for any placement of 650 points in a disk of radius 16, there exists at least one annulus of inner radius 2 and outer radius 3 containing at least 10 points.
We are given a grid of size $n times m$, each cell either containing a target represented by or empty represented by .. Shel has a shotgun that fires in one of four diagonal directions: right-down, left-down, left-up, or right-up.
The statement as written can only be meaningful if the second triangle has side lengths $\sin x$, $\sin y$, $\sin z$.
We have a two-player game on a rectangular grid with height h and width w. Alice’s chip starts at (xa, ya) and can move down, down-left, or down-right. Bob’s chip starts at (xb, yb) and moves up, up-left, or up-right.
We have an array a of length n. Another array b contains m values, where m is at least n. We are allowed to choose exactly n elements from b, then arrange those chosen elements in any order to form a new array c.
We are given an array of integers and a set of queries. Each query specifies a starting index s, a step size d, and a count k. For a query, we must sum k elements of the array taken at indices s, s+d, s+2d, ...
The task is to transform an initial arrangement of cats in boxes into a target arrangement using the fewest operations. Each box either contains a cat or is empty, and the initial state is given by a binary string s, while the target state is given by a binary string f.
We are given the four vertices of a square on a 2D coordinate plane. The points are presented in arbitrary order, so we do not know which point is the bottom-left corner, top-right corner, and so on. The square has two special properties.
Stepan needs to send a series of messages at strictly increasing moments in time. His phone starts with a finite charge, loses a constant amount per unit of time while it is on, and consumes a fixed cost if he turns it off and then back on.
We are given an array of integers, each between 1 and some maximum value $x$. We want to make every element equal using a special operation: select a contiguous subsegment of the array and a value $k$ not currently present in that subsegment, then replace every element in that…
We are given three strings of equal length, and we need to construct a template string such that the first two strings match the template while the third one does not. Each position in the template can be either lowercase or uppercase.
We are asked to construct an array of integers with a very specific property: the total number of its increasing subsequences should equal a given integer $X$.
We have a row of monsters, each with an attack value ai and a defense value di. Monocarp casts a berserk spell so that monsters attack their immediate neighbors each round.
We are given a set of sticks, each with a length that is a power of two. The input does not give the actual lengths directly but rather exponents $ai$ such that the stick's length is $2^{ai}$.
We are given several cities placed along a one-dimensional number line. Each city has a coordinate, and the coordinates are strictly increasing. For each city, there exists a unique "closest" city, meaning that no two cities are equally close to it.
We are given a tree with n nodes, each colored with some integer between 1 and n. The task is to count the number of simple paths of length at least two such that the first and last nodes have the same color, and no intermediate node shares this color.
We are given a row of slimes, each with a positive size. The slimes interact in a simple but constrained way: a slime can eat an adjacent slime if it is strictly larger, and upon eating, it grows by the eaten slime’s size.
We are given a binary string s of length n and a number k representing the maximum number of allowed operations. Each operation can either swap two characters of the string or remove all leading zeros and then reverse the string.
We are given a row of cells, each either containing a chip or empty. The goal is to move chips leftward into contiguous groups by repeatedly picking a chip and moving it into the closest empty cell to its left.
We are given an array c of positive integers and multiple queries asking whether certain subarrays of c are good.
We have a line with our character at position 0 and monsters positioned at some coordinates $xi$, each with health $ai$. Every second, we can fire up to $k$ bullets, reducing the health of monsters we choose.
We have a straight line with n points, each occupied by a ship. Some of these points already host harbours, each with an associated value. A ship at a point incurs a cost if it were to "move" to the next harbour to its right.
We are asked to model a stochastic process of repeatedly cutting a rectangular sheet of paper and discarding parts of it, and then compute the expected number of steps until its area falls below a threshold.
I can't write a correct editorial for Codeforces 1924F from the problem statement alone. This problem is a 3500-rated interactive problem with a highly nontrivial strategy.
We repeatedly perform the same fold on a square sheet. Every fold takes the current square, folds all four corners to its center, and produces a smaller square whose side length is multiplied by $1/sqrt2$.
We are working with strings made only from two types of parentheses, and we fix how many opening and closing brackets we must use. Each test case gives three numbers: how many '(' we must place, how many ')' we must place, and a target parameter k.
We are given a string s and two integers n and k. Conceptually, we are asked to check if every string of length n that can be built using the first k letters of the alphabet appears somewhere as a subsequence in s.
We have a graph on n children. Only m pairs are marked as friends, and each friendship edge has an initial weight f. The teacher performs exactly k excursions. During each excursion, one unordered pair of children is selected uniformly at random from all possible pairs.
We are asked to split an integer $x$ into exactly $n$ positive integers whose sum is $x$, in a way that maximizes the greatest common divisor of these integers. The input gives multiple test cases, each with values for $x$ and $n$.
We have a fixed $7 times 7$ board whose cells are either black or white. A configuration is considered bad if there exists a black cell whose four diagonal neighbors are also black. Such a pattern looks like an X centered at that cell.
We are asked to separate music from sleeping students in a dormitory modeled as a tree. Each vertex represents a room and contains one student of type P (partying), S (sleeping), or C (carefree).
We are given a set of non-negative integers and asked to partition them into groups so that within each group, no two numbers share a 1-bit in the same position across the first 31 bits.
Vladislav has a deck of cards numbered from 1 to n. He wants to arrange them in a sequence with a peculiar rule. First, he takes all odd numbers and lays them out in increasing order. Then he takes all numbers that are twice an odd number and lays them out in increasing order.
For every test case, we are given a number n. Vlad writes all integers from 1 through n on the board. Then each integer is replaced by the sum of its decimal digits. The task is to compute $$sum{i=1}^{n} text{digitSum}(i)$$ where digitSum(i) is the sum of the digits of i.
Place the isosceles triangle in coordinates as
The task is simple: for each string of length five consisting only of the letters A and B, determine which letter occurs more frequently. Each test case provides one such string, and we have multiple test cases to process.
We are given a very small binary image, typically at most 10 by 10 cells. Every cell is either empty or filled. The grid contains exactly one connected geometric figure formed by ones, and that figure is guaranteed to be either a perfect square or a centered triangle (upright…
We are given a one-dimensional strip of cells, where each cell contains a “paint charge” with a fixed radius. Activating a charge at position i does not just affect that cell, it paints a contiguous segment either extending left or extending right by exactly a[i] cells…
We need to build a permutation of the numbers from 1 to n such that every contiguous segment of length k has almost the same sum. More precisely, if we compute the sum of every window of length k, the largest and smallest of those sums may differ by at most 1.
We are asked to find a simple cycle in an undirected, weighted graph where the minimal edge in that cycle is as small as possible. The input is a series of graphs: each graph is described by the number of vertices, the number of edges, and a list of edges with weights.
The problem gives you an array of integers and a series of queries, each specifying a segment of that array. For each query, you are asked to find two positions within the segment such that the values at these positions are different.