brain
tamnd's digital brain — notes, problems, research
43815 notes
We are asked to determine which episode Polycarpus has not watched in a season of a TV show. He has watched n - 1 episodes out of a total of n, each numbered consecutively from 1 to n.
We are asked to teach Devu a set of subjects, each consisting of a certain number of chapters. Devu starts with a fixed amount of time required per chapter, and after completing each subject, the time per chapter decreases by exactly one hour for the next subject, down to a…
We are given an array of distinct integers, and we need to split it into exactly k non-empty groups. Among these groups, exactly p must have an even sum, and the remaining k - p must have an odd sum.
We are distributing a total of n identical sweets into f distinct friends, with the rule that every friend must receive at least one sweet. So the outcome of a distribution can be viewed as an ordered array a1, a2, ..., af of positive integers whose sum is n.
The task is to simulate how a child chooses an answer on a multiple-choice question with four options, labeled A through D. Each option has a textual description.
We are given a connected undirected graph where each node represents a zoo area and carries a value describing how many animals live there. For any ordered pair of distinct areas $p$ and $q$, we look at all simple paths connecting them.
We are asked to reconstruct a set of distinct integers from 1 to a given upper bound, such that the sum of a special function applied to each element equals a target value. The special function, lowbit(x), extracts the lowest set bit of x in its binary representation.
We have up to 2000 candies. Each candy has a type, either 0 or 1, a required jump height, and a mass. Om Nom starts with jump power x. He may eat any uneaten candy whose height is at most his current jump power. After eating a candy with mass m, his jump power increases by m.
We are asked to optimize revenue from a mobile app that has both a free version with ads and a paid version without ads.
Each level can end up in one of three states. State 0 means we ignore it and gain no stars. State 1 means we complete it for one star and spend a[i] time. State 2 means we complete it for two stars and spend b[i] time.
We are given k game levels. Each level is an n × m grid of characters. A level can be transmitted in two different ways. The first option is to send the entire grid from scratch. Since every cell must be transmitted, the cost is n m.
We have monsters placed on an infinite integer line. Consecutive monsters immediately stick together and form a block. A move chooses one entire block and slides it left or right until it collides with another block. After the collision, the two blocks merge.
We are asked to compute how many spiders Om Nom sees if he starts walking from each cell in the top row of a rectangular park. The park is represented as an n × m grid where some cells contain spiders with an initial direction: left, right, up, or down.
We are given a rectangular grid with n rows and m columns. Each intersection of horizontal and vertical lines - each "node" - is colored either black or white. Additionally, every unit square in the grid has diagonals drawn.
We have an $n times m$ grid of vertices. Two vertices are connected if they share a side, and also if they are opposite corners of the same unit square. In other words, every cell contributes all four edges of the square plus both diagonals.
We are given a positive integer, which we can treat as a string of decimal digits, and a maximum number of allowed adjacent swaps, k. The goal is to transform this number into the largest possible number by rearranging digits, but each move can only swap two neighboring digits.
The input describes a polyline that alternates between rising and falling diagonal segments. The length of the $i$-th segment is $ai$.
We have a sequence of stones, each with a numeric cost. Kuriyama Mirai wants to ask two types of questions repeatedly: in the first type, she asks for the sum of the costs of stones in a contiguous segment of the original sequence; in the second type, she asks for the sum of…
We are asked to count numbers in a given range [l, r] (expressed in base m) that satisfy a certain “value” constraint. Each number starts with value zero. We are given n patterns, each a sequence of digits in base m, with an associated integer value.
The notebook pages are numbered from 1 to n. The sequence a describes the order in which Ryouko will read information. If two consecutive pieces of information are on pages a[i] and a[i+1], she must turn The total effort is the sum of these distances over all consecutive pairs.
We have a dynamic binary grid. A cell containing 1 is lit, a cell containing 0 is dark. Two kinds of operations appear. A modification flips one cell. A query asks for the largest all-1 rectangle whose border contains a given cell (x, y). The cell does not need to be a corner.
We are given a collection of apples where every apple weighs either 100 grams or 200 grams. All apples must be distributed between two people, and each apple must go entirely to one person because apples cannot be cut.
We are given a single string of uppercase letters. Our goal is to identify all prefixes of the string that are identical to some suffix, and for each such prefix, count how many times it occurs anywhere inside the string as a contiguous substring.
We are given a permutation of integers from 1 to n, which means each integer in that range appears exactly once in the array. The goal is to sort this array in increasing order, but with a special restriction on the swaps we can make.
We are asked to simulate a football tournament between n teams, where each team has a home kit and an away kit with distinct colors. Every team plays a home and away game against each other team. By default, the home team wears its home kit and the away team wears its away kit.
We have two sequences. A profitable move chooses a non-empty prefix from each sequence, with the requirement that the last element of the chosen prefix in the first sequence is equal to the last element of the chosen prefix in the second sequence.
We are given an array of integers and a limited budget of swap operations. Each swap allows exchanging any two positions in the array, and we can perform at most k such swaps.
We are asked to count sets of intervals within the integer range from 1 to n, such that the largest collection of non-overlapping intervals in the set has exactly size k.
We are given a table of size n × m, where each cell contains either a zero or a one. Sereja wants to modify at most k cells so that the table satisfies a very specific property: each connected group of identical numbers must form a perfect rectangle aligned with the table’s…
We are asked to merge multiple patterns into a single pattern that intersects with all of them, minimizing the number of question marks. Each pattern consists of lowercase letters and question marks, where a question mark matches any letter.
We are given one long string that contains only lowercase letters, digits, , @, and .. We must count how many substrings of this string are valid e-mail addresses. Substrings are distinguished by their positions, not by their textual contents.
We are given a set of computers, each with a measured maximum Internet speed. There are fewer participants than computers, and each participant must get a separate computer.
We are asked to simulate painting a slogan on a linear banner that is divided into n squares, one character per square. The painter can use a ladder that initially stands in front of the k-th square.
We are given four players split into two teams of two. Each player has two independent strengths: one for defending and one for attacking. Before the match, each team assigns one player to attack and the other to defend.
We are simulating a processor with several cores and several memory cells. Time is divided into cycles. For every cycle, each core receives either a command to do nothing or a command to write into a specific memory cell. The interesting part is how deadlocks occur.
We are asked to check whether a password string is "complex enough" based on four criteria. The password is a sequence of up to 100 characters containing uppercase letters, lowercase letters, digits, and a few special characters.
We are given a set of $n$ points on a 2D plane with floating-point coordinates. The task is to find the smallest possible angle of rotation around the origin that ensures all points can be covered by a half-plane (a straight line that divides the plane into two parts).
The input is a single string that visually looks like a tiny ASCII “program”. Inside it there are special symbols forming a structure, and within this structure there are placeholder positions that behave like variables.
The task is to read a single line containing two non-negative integers separated by whitespace and output their arithmetic sum.
We are given a single integer $a$, and we are asked to compute a certain count associated with binary strings of length $a$. Each position in such a string can be thought of as a switch that is either off or on, but the strings we are allowed to consider are not arbitrary.
The problem presents a number x that represents a dome's height in some scaled system. Our task is to find two positive integers, a and b, both between 1 and 10 inclusive, that encode this height according to the formula $x = a cdot sqrt{b}$.
This is one of Codeforces' April Fools problems. There is no real algorithmic input. The judge provides a special language called "Secret" through the custom invocation system. The task is to identify what that language actually is and submit a program written in that language.
At first glance, the problem seems almost absurdly simple: you are given an integer between 1 and 16, and you need to output a single integer corresponding to that input.
We are given two short strings representing sequences of moves in a fictional duel between two teams. Each string is built from a small alphabet that visually looks like emoticon fragments, and each valid move is actually encoded using two characters.
The problem gives us a list of integers representing quantities of some alchemical ingredients. The goal is to determine the greatest common divisor (GCD) of these quantities. In other words, we want to find the largest integer $d$ such that each given number is divisible by $d$.
We are given an integer sequence of length $n$ and two additional parameters: $k$, the maximum number of elements we are allowed to insert, and $d$, the intended difference of an arithmetic progression.
We are given an integer matrix of size n by m. Each cell contains a positive integer. The task is to find the largest rectangular submatrix where all the elements are distinct. The “largest” is measured by area, meaning the number of cells inside the rectangle.
We are given an array and a sequence of range operations. Each operation picks a segment $[l, r]$ and a parameter $k$, and for every position $j$ inside that segment we add a value that depends on how far $j$ is from the left endpoint $l$.
We are given two positive integers, a and b, which are the lengths of the legs of a right triangle. The task is not to check whether such a triangle exists, it obviously does.
We are given a linear maze with n+1 rooms, numbered from 1 to n+1. Each room 1 through n has two portals. The first portal always moves forward to the next room, i+1. The second portal moves backward to some previous room, p₁ through pₙ, where pᵢ ≤ i.
We are given a large universe of numbered blocks from 1 to 1,000,000. Some subset of these blocks, called $X$, has been removed from Chris’s set. From the remaining blocks, we need to choose a non-empty subset $Y$ so that a very specific weighted balance condition holds.
We are given a connected undirected graph, and we are asked to completely decompose its edges into length-2 paths.
We are given an n×n binary matrix, meaning every element is either 0 or 1. The "unusual square" of the matrix is defined as the sum over all rows of the dot product of row i with column i, computed modulo 2.
We are given a row of dominoes, some of which are initially pushed to fall either left or right, while others are standing upright. Each second, a falling domino pushes its immediate neighbor in the same direction.
We are given a row of vertical stacks of cubes. Each position in the row holds a column, and the input array describes how many cubes are stacked at each position. Then a “gravity switch” happens.
We have a robot standing on an infinite 1D strip of cells indexed by integers, starting at cell 0. The robot is given a sequence of moves, each either left (L) or right (R). Before the robot starts, we can place obstacles on some cells, except cell 0.
We have a one-dimensional Minesweeper field represented as a string of length n. Each character can be a bomb '', an unknown '?', or a number 0, 1, or 2. The numbers indicate how many bombs are immediately adjacent to that cell.
We are asked to reconstruct an undirected connected graph from a list of shortest distances from one vertex, under the constraint that each vertex can have at most k edges.
We are given an odd-sized square grid of letters. Each cell contains a lowercase English letter. The task is to check whether the letters form a perfect "X" pattern.
Valera runs around the perimeter of a square stadium. The square has side length a, and the route follows the boundary in counterclockwise order. The starting point is the bottom-left corner (0, 0).
We are given a square matrix $a$ of size $n times n$ whose elements are all non-negative integers. The matrix can be thought of as a weighted adjacency matrix of a graph with $n$ nodes, where $a{ij} 0$ indicates a direct edge from node $i$ to node $j$.
We are asked to construct a special type of undirected graph. The graph has n vertices and a parameter p, and it must satisfy two global conditions. First, the total number of edges is exactly 2n + p. Second, no subgraph of k vertices may have more than 2k + p edges.
We are asked to distribute a given number of nuts into boxes, but the boxes are not simple containers. Each box can be split into sections using “divisors,” and every section can hold at most a certain number of nuts.
We have a row of trees, each with a given height. The Queen wants the trees arranged in perfect arithmetic progression: the difference between consecutive tree heights must be exactly $k$.
Vanya has found a subset of his playing cards, each card labeled with an integer between $-x$ and $x$. He wants the total sum of all his cards to be zero. We need to determine the minimum number of additional cards he should find to achieve that zero sum.
We are asked to arrange a set of cards, some marked with zero and some with one, in a line so that no two zeros are adjacent and no three ones are consecutive. We know the counts of each type of card upfront: n zeros and m ones.
We have a row of domino tiles. Each tile has a number on its upper half and a number on its lower half. For every tile, we may either leave it as it is or rotate it by 180 degrees. Rotating a tile simply swaps its upper and lower values. Each rotation costs one second.
We are given an array of non-negative integers a with length n and a number m in binary form. We want to select a subset of indices from 0 to n-1 and sum the corresponding a[i] values, but with a twist: the subset corresponds to the binary representation of some integer x…
Codeforces 353E: Antichain
We are given a line of schoolchildren represented as a string of letters M and F, where M indicates a boy and F a girl. Each second, any boy standing immediately in front of a girl swaps positions with her. This process repeats until no boy is in front of a girl.
Each cube contains a two digit number. We must split the 2n cubes into two heaps of exactly n cubes each. After the split, Valera may choose any cube from the first heap and any cube from the second heap.
We are asked to construct a bracket sequence of length n·m, where n is a small number up to 20 and m is much larger, up to 10^7, and is even. Each position in the sequence can be either an opening bracket ( or a closing bracket ).
Jeff has a list of 2n real numbers and he wants to round them in pairs so that the total sum changes as little as possible. Each operation consists of taking two unused numbers: one is rounded down (floor) and the other rounded up (ceiling).
We are given a sequence of integers, and we are allowed to flip the sign of any element. The goal is to minimize the number of inversions in the sequence. An inversion occurs whenever a larger number appears before a smaller number in the sequence.
For each query we look at a subarray of the given array and ask for its beauty. A single operation chooses several equal values whose positions form an arithmetic progression, removes them, and then allows us to reorder everything that remains. That last sentence is the key.
We are asked to model a two-player game played on a permutation of integers from 1 to n. Jeff moves first and can swap any adjacent elements.
Label the people around the circle as a cyclic sequence of 60 vertices, each colored either $B$ (boy) or $G$ (girl), with exactly 30 of each color.
Let
Let integers $a \le b$ be such that the required sum is
The relation
We are given a set of points on an infinite grid, each point containing a single bomb. A robot starts at the origin and must eventually destroy every bomb, but it cannot simply “teleport” to them.
We are given an undirected, simple, connected graph with $n$ vertices and $m$ edges. In addition, a subset of vertices $a1, a2, dots, ak$ is designated as “special”.
We are asked to count "owls" in a geometric picture composed of segments and circles. An owl is defined as a combination of two circles and a segment where the circles are reflections of each other across the segment, have identical radii, do not overlap, and the segment…
We are asked to help Valera set a time limit for a programming problem. He has a set of correct solutions, each with a known runtime, and a set of wrong solutions, also with runtimes.
Place the circumcenter $O$ as a reference point and represent the triangle on its circumcircle.
Igor wants to paint the largest possible number on a fence using a limited amount of paint. Each digit from 1 to 9 has a specific paint cost, and zero cannot be used.
We are given a queue of people waiting to buy cinema tickets. Each person holds a bill worth 25, 50, or 100 rubles, and each ticket costs 25 rubles. The clerk starts with no money and must sell tickets in the exact order of the line, giving correct change if necessary.
We are given an array of integers and a collection of subsets, each referencing indices in the array. Two types of operations are performed repeatedly: querying the sum of the elements of a subset, and adding a value to all elements of a subset.
Let $n_k$ be the repunit of length $k$, so
We are given a rooted tree where only the leaves initially contain apples, while internal nodes are empty. Each leaf contributes a fixed number of apples, and the “weight” of any subtree is defined as the total number of apples in all leaves inside that subtree.
We are given a weighted tree with n towns. Some of these towns contain monasteries, and each monastery hosts exactly one pilgrim.
We are given a rectangular grid of size n by m, where each cell is either free or blocked. Two turtles start at the top-left corner, cell (1,1), and both want to reach the bottom-right corner, cell (n,m).
We are given a group of friends who will repeatedly play a game. Each round of the game has exactly one person acting as a supervisor, while the remaining $n-1$ people participate as players.
Let $P(x)\in\mathbb{Z}[x]$ and suppose there exist distinct integers $x_1,\dots,x_n$ with $n\ge 3$ such that
We are given a list of n integers and need to arrange them in a row such that the sum of differences between consecutive numbers is maximized. Concretely, if the arrangement is $x1, x2, dots, xn$, the value is calculated as $(x1 - x2) + (x2 - x3) + dots + (x{n-1} - xn)$.
The process can be encoded in terms of the coefficients $a$ and $b$ of the quadratic $x^2+ax+b$, starting from $(a,b)=(10,20)$ and ending at $(20,10)$.
We are given a permutation of numbers from 0 to n − 1, stored in an array where each index represents a position and the value at that index represents where that position “points”. A position i is called a fixed point if the value stored at that position is exactly i.
We start with a number a and want to reduce it down to b using two types of moves. One move simply decreases the current value by 1. The other move is more interesting: we pick one of the given numbers xi and subtract the remainder of the current value when divided by xi.
We start with a finite set of distinct positive integers. Two players alternate turns, and on each turn a player is allowed to take any two existing numbers, compute their absolute difference, and insert that value into the set if it is not already present.
Let $x,y \in \mathbb{Q}\setminus{0}$ satisfy