brain
tamnd's digital brain — notes, problems, research
43815 notes
There are exactly (N=5{,}000{,}000) people in Diegopolis. Each person independently survives the snap with probability (1/2). Let (X) be the number of survivors, so (X) follows a binomial distribution with parameters (N) and (1/2).
There are (2N) numbers that will be placed on a circle. Diego chooses one contiguous block of exactly (N) positions, and Googles receives the other (N) positions. Since the two blocks cover the entire circle, if Diego gets a sum of (X), Googles gets the total sum minus (X).
The tree itself looks central to the statement, but the useful representation is not the edge weights. Root the tree at any vertex, say vertex 1, and let (hv) be the XOR of the edge weights on the path from the root to (v).
The Joker counts seconds starting from one. At second (t), he says the representation of (t) in base (a), without leading zeroes. For example, in base (3), the sequence starts with (1,2,10,11,12,ldots).
We have two families of straight lines. The first family contains lines of the form (y=x+p), and the second contains lines of the form (y=-x+q). The values (p) are distinct integers, as are the values (q).
We have a (2times n) grid containing exactly (2n) lettuce leaves. Each leaf has a nonnegative energy value, and Kolya may freely permute all leaves before the turtle starts.
We have a directed weighted graph of cities. City 1 is the capital, and every directed road u - v has a capacity w, meaning a cargo of weight at most w can traverse that road. For a fixed city s, a route from s to the capital can use several roads.
We have a circular pizza and (n) people. Person (i) needs one sector whose angle is exactly (alphai) degrees. The sectors can be placed anywhere on the pizza and do not have to appear in the input order. Any unused part of the pizza can stay in the box.
We have an infinite sequence of rooms numbered (0,1,2,ldots), and every room always contains exactly one guest. Guests belong to groups. Initially every room contains a guest from group (0). A type 1 operation creates a new group.
We have an N x M array whose entries are cards showing one of 6, 7, 8, or 9. A card may be rotated in place, but cards cannot move between cells. After choosing which cards to rotate, the resulting array must be unchanged by a 180-degree rotation.
The encrypted message is not an arbitrary collection of numbers. There are exactly (2^N) values, one for every subset of the original (N) character codes.
We are given a word whose characters are already sorted by their ASCII values. We replace every character by its ASCII code, obtaining an array of (N) positive integers.
For each test case, we have three positive integers (A), (B), and (C). We first add (A) and (B), then divide that sum by (C). The required output is the decimal representation of the result with exactly 50 digits after the decimal point.
We have an (n times n) grid, with the Joker at cell ((a,b)). We need to count cells inside the grid whose Manhattan distance from the Joker is exactly (d). For a cell ((x,y)), the condition is [ ] Without the grid boundaries, these cells form a diamond around ((a,b)).
We have an array of nonnegative values a 1 ,…,a n , one value for each spectator. Each police officer watches one contiguous interval [l i ,r i ].
The board is an undirected simple graph. A move does not remove a vertex, it removes an edge, and the next move has to use an edge sharing an endpoint with the edge removed immediately before it. An edge can be used only once because it disappears after being selected.
I can write the editorial, but the problem statement and samples are missing from your prompt, and I cannot reliably reconstruct the task from the title alone. Please provide the actual statement so I can derive the correct algorithm and tests. Waiting for your answer
There are (n) residents and (n) cats. Resident (i) owns cat (i). Each acquaintance relation is represented by a directed edge from resident (a) to cat (b), meaning that resident (a) knows cat (b). Every resident knows their own cat, so every vertex has a self-loop.
We have (n) distinct positive integers (a1,ldots,an). A card contains some positive integer (x). Taking that card lets us perform exactly one operation on exactly one array element: multiply it by (x), or divide it by (x) when the division is exact.
We have an (n times m) rectangular grid whose cells are colored with two colors. Two cells are neighbors when they share a side. A coloring is valid if every cell has at most one neighbor with the same color.
The invariant is that before processing each new right endpoint, left points to the smallest possible left boundary after all previous shrinking.
We need to reconstruct the dimensions of a rectangular piece of land from its area. The input contains a single integer n, representing the rectangle's area. We need to print two positive integers height and width whose product is exactly n.
Artem starts with a cyclic permutation of the numbers from (1) to (n). For every position, he looks at that position and the next two positions, wrapping around at the end. Thus, from a permutation [ [a1,a2,ldots,an] ] he produces the (n) unordered triples [ {ai,a{i+1},a{i+2}}.
We have a correct-answer string of length (n), and (m) students, each represented by another string of the same length. At every question, a student's answer is either correct or incorrect according to the corresponding character of the answer key.
We have an initial account balance s and n transactions that must all happen during the next m days. Transaction i changes the balance by count[i], but its exact day can be any day in the inclusive interval [from[i], to[i]].
We start with a set containing 0, 1, and 2. One operation chooses any two numbers x and y already in the set and inserts x 2 −y. The inserted value must stay between 0 and 10 18, and we may perform at most 43 operations.
We have a prime modulus (p), a subset (S) of residues modulo (p), and another subset (V). For every ordered pair ((a,b)) with both values in (S), we evaluate [ F(a,b)= frac{(2a+3b)^2+5a^2}{(3a+b)^2} + frac{(2a+5b)^2+3b^2}{(3a+2b)^2} pmod p.
We have a string w of length at most 200000. We want to find the most repetitive substring inside it, where the repetition is allowed to stop halfway through the next copy. Suppose a substring has period p and length L. Its exponent is L / p.
The golf course is an axis-aligned rectangle of width w and height h. A ball starts at an integer point (x0, y0) strictly inside the course and moves northeast, increasing both coordinates by exactly one inch per second.
We need to count strings over an alphabet of size (k), considering every non-empty length from (1) through (n). A string is valid if it is itself a palindrome or can be split into two palindromes. The two pieces may have different lengths and may even be identical.
We have a box of length n containing two bars on parallel rails. The short bar has length a, the long bar has length b, with a < b. The long bar carries a stopper at each end, and the short bar must remain completely between those two stoppers.
For each test case, we are given an integer (N), and we need to compute the bitwise XOR of every integer from (1) through (N): [ 1 oplus 2 oplus 3 oplus cdots oplus N. ] The order does not matter because XOR is associative and commutative.
На экране находятся два целых числа a и b, причём a <= b. За один ход можно выбрать одно из них и заменить выбранное число либо на округлённое вверх…
We encode each lowercase letter by its position from 0 to 25. The first number a[0] fixes the exact first letter of the code. Every later number a[i] specifies the absolute difference between the numerical values of two consecutive letters.
We have a rectangular cabinet standing in the corner of a room. Its two dimensions along the walls are a and b. A door of length d is mounted at a distance l from the corner.
We have (n) passengers sitting in seats numbered from left to right. Passenger (i) becomes hungry at time (ti). The hot-water tank is to the left of everyone, and only one passenger can use it at a time.
We have (n) pipes. The (i)-th pipe has length (sqrt{ai}), where (1 le ai le 10^6). Mario wants to connect some of these pipes into one polyline starting at the origin. Every joint, including the final faucet, must have integer coordinates.
There are n cupcakes on the table, and Mahmoud makes the first move. On each turn, the current player may eat exactly one cupcake. If the current number of cupcakes is even, the player also has the option to eat exactly half of them.
We start at a grid point (x, y) and receive a string describing a sequence of unit moves. Each character changes exactly one coordinate: U increases y, D decreases y, L decreases x, and R increases x.
We have a row of (N) cubes, and each cube is either painted or left untouched. A type 1 rule requires at least (K) painted cubes inside a particular interval ([L,R]). A type 2 rule requires at least (K) painted cubes outside that interval.
We have a permutation (a) containing every integer from (1) to (n) exactly once. For every prefix (a1,ldots,ai), consider its largest and smallest values. Their difference is (hi).
There are (n) players and (m) rounds. In every round, a player either participates in one match or receives a bye. A match contains either two or three games, and the input directly gives how many games each player won and how many were drawn.
We have a circular array. In one operation, we choose one position and replace its value by either the minimum or the maximum of that position and its two neighbors.
We have a hidden array a of n distinct positive integers. We do not receive its values directly. Instead, an interactive judge lets us ask two kinds of questions. A type 1 query gives the exact value at one position.
Alice and Bob each start with an array of (n) integers. On every turn, a player deletes one value from their own array, with Alice moving first. Deletions continue until each array contains exactly one value.
We have two weighted trees on the same set of vertices, with vertex labels (1) through (N). For two labels (i) and (j), their distance is not measured in either tree alone.
We start with two permutations (A) and (B), both containing every integer from (1) to (N) exactly once. We may rearrange (A), but only by swapping neighboring elements. The goal is not to construct one particular maximum arrangement.
We have a binary array whose entries are container capacities, either 1 or 2. The goal is to transform the current array into a target array containing exactly the same number of each type. An allowed operation reverses either two consecutive entries or three consecutive entries.
Each bridge can be represented by the half-open interval ([Si,Ei)). A bridge is visible from the small arc between consecutive points (i) and (i+1) exactly when that arc lies inside this interval. The input contains (N) weighted bridges.
We have a directed graph whose edges carry distinct integer colors. Starting from (S), we may traverse any outgoing edge, and we are allowed to revisit vertices and edges. The only requirement is that the walk eventually reaches (T).
The original tree is rooted at vertex (1), and every vertex (i1) has a parent (pi<i) and an edge weight (wi). The multiset containing all these parent values and all these edge weights has (2n-2) elements, but their roles are lost because the array was shuffled.
We have a three-dimensional rectangular grid with dimensions m × n × p. A cell is either solid wreckage, empty space, the robot's starting cell R, or the teleporter T. The robot occupies an empty cell and is initially attached to some neighboring solid wreckage.
We have a complete undirected graph on an odd number (n) of vertices. Every one of its (frac{n(n-1)}2) edges has a positive weight. We must partition all edges into cycle-arrays.
For a fixed depth coordinate x, the first projection tells us which y-positions must contain at least one cube, while the second projection tells us which z-positions must contain at least one cube. A cube at (x,y,z) simultaneously creates the projection cells (x,y) and (x,z).
Root the given tree at vertex 1. The game can be viewed more naturally as a game on another graph. Create a graph whose vertices are the tree vertices, and connect two vertices whenever one is an ancestor of the other in the rooted tree.
We have (n) people with known ages. Every person must travel either as a driver or as a passenger in a car, or alone on a motorcycle. A car has capacity (k), exactly one of its occupants is the driver, and that driver must be at least (lc) years old.
Let the input length be (L=2n). The input is a multiset of lowercase letters, because the original cyclic order has been destroyed and only the symbols remain. We have to rearrange those letters into a cycle such that the (L) cyclic substrings of length (n) are all different.
Steve has a collection of quests, and every quest can be completed at most once. Before the first level is completed, quest (i) gives (xi) experience and costs (ti) minutes. After the first level is completed, the same quest gives only (yi) experience and costs (ri) minutes.
There are (n) bus stations connected by an undirected, connected graph. Every highway has unit length, so the distance between two stations is their ordinary shortest path length in the graph.
We have an access sequence a[1..n]. For a chosen cache capacity m, the LRU cache maintains its items from most recently used to least recently used. Whenever an item is accessed, it becomes the first item in the list.
We have (n) rabbits with initial weights (w1,w2,ldots,wn). On each of (k) mornings, exactly one rabbit receives one additional unit of weight.
For each test case, we need to split the integer n into two positive integers x and y such that x is prime, y is composite, and x + y = n. The two numbers must both be strictly smaller than n. If no such split exists, we print -1.
On each day, one new rental set becomes available. A set is identified by two values: (ai), the size of each of its two equal piles, and (bi), the amount Alice pays to rent that set.
We have exactly six old banners. From each banner, we must choose exactly one character, giving us exactly six characters in total. We may reorder those six characters freely, and the final word must be harbin.
We start with a very long array of gift types. Position (i) initially contains (gi). We may arbitrarily exchange gifts between contestants, so the final array can be any permutation of the original multiset of gift types.
We have an axis-aligned rectangular field and two disjoint line segments strictly inside it. The car is a point, and every point of its route must be equally distant from the two segments.
Every integer from (0) through (2^m-1) can be viewed as an (m)-bit binary string, padding leading zeroes when necessary. The function (F{m-1}(a,b)) counts how many consecutive bits from the most significant side are equal before the first mismatch.
A subarray is interpreted as one complete multitest input. Its first value is the number m of graph edges, and the next 2m values are grouped into m unordered vertex pairs.
The construction starts with the sequence [1]. To move from order m to order m+1, we scan every length-m window of the current sequence. Whenever such a window is a permutation of 1..m, we insert the new value m+1 followed by that same permutation immediately after the window.
Think of the metro system as a weighted graph. Every station is a vertex, consecutive stations on the same line are connected by an edge, and the edge weight is the travel time between those stations.
We have three chests containing a, b, and c coins. In one second, we choose exactly two different chests and add one coin to each chosen chest. We need all three chests to end with the same number of coins, and we want the minimum number of seconds.
We have n solution files, and every file occupies exactly x GB. A single flash memory can hold at most a GB, and a file must stay entirely inside one memory. The goal is to find the smallest number of flash memories needed to store all n files.
There are n multiple-choice questions, and Ayoub answered each question with one letter from a through e. The crucial extra information is that the correct answer is the same letter for every question. We do not know which of the five letters it is.
We have a sequence of n flagstones, and each flagstone has a color a[i]. We need to count every nonempty subset of positions whose flagstones all have exactly the same color.
Each player owns an array of length n. For a fixed target sum k, a pair of positions (i, j) is good when i < j and the two values add up to k. We need to count the good pairs independently in Mahmoud's array and Bashar's array, then compare the two counts.
There are n houses arranged in a line, and house i contains a[i] coins. Bashar may choose any house as his starting point and any house as his stopping point. While walking between them, he visits every house on that segment and collects all its coins.
Bashar wants to buy exactly x shawerma sandwiches. Every sandwich costs exactly 2 JDs, so the required amount of money is the price of one sandwich multiplied by the number of sandwiches. The input contains one integer x, representing the number of sandwiches Bashar wants to buy.
We have a connected simple undirected graph. Swiper chooses a nonempty proper set of vertices and removes those vertices together with all incident edges. The remaining vertices must keep the same degree modulo (3) that they had before the removal.
We maintain a dynamic set (A) of distinct integers, initially empty. After every insertion or deletion, we must determine how small the MEX can become after choosing some XOR mask (x) with (0 le x le k).
We work with a mutable string of parentheses. A substring is considered beautiful by counting how many of its cyclic rotations form a correct bracket sequence.
We have a building with floors numbered from (1) to (n). Some floors have working number signs. The sorted array (a1,ldots,at) contains exactly those signed floors, with floors (1) and (n) always included. Arthur initially stands on a uniformly random floor.
We have an (n times n) chessboard. We may place at most (n) checkers on individual cells. Every remaining cell must be covered by exactly one domino, where a domino always covers two cells sharing a side.
We have a weighted tree with (N) vertices. Each edge stores an integer, and for any two vertices we define their path value as the XOR of all edge weights on the unique path connecting them. The task is to add these path values over every unordered pair of distinct vertices.
We need to choose an integer center (X, Y) and an integer height H for an axis-aligned square pyramid. Because every side has slope exactly 45°, moving one unit horizontally or vertically away from the center lowers the pyramid by exactly one unit.
The problem is from the MEX Foundation Contest, Gym 102412, Problem J. The official limits are (2le nle 2cdot10^5), (1le kle n), (0le aile n), with a 4 second time limit and 512 MiB of memory. We have a nonnegative integer array (a).
We have a set (S) with (n) elements, and every subset of (S) must be painted either red or blue. For a subset (T), painting it red costs (RT), while painting it blue costs (BT). The costs may be negative, so the goal is not simply to choose the cheaper color independently.
We have a connected undirected graph. One vertex, called the source, was chosen secretly. For every vertex (v), we are given the shortest-path distance from the source to (v), but only its remainder modulo (3). The task is to recover the source vertex.
We have a directed acyclic graph with (n) vertices and exactly (2n) edges. The edges are numbered from (0) to (2n-1), and edge (i) has value (lfloor i/2rfloor). Thus every value from (0) through (n-1) occurs on exactly two edges.
We have a tree whose vertices may or may not currently contain a chip. A query toggles one vertex between these two states. After every toggle, we need the minimum total number of edge traversals required to gather all currently present chips at one common vertex.
Think of every party member as a vertex. There are (n) vertices on the left, numbered (1) through (n), and (n) vertices on the right, numbered (n+1) through (2n). Every problem creates one edge between one left vertex and one right vertex.
We have (n) hunters, and each hunter occupies a distinct point ((xi,yi)) on the plane. We need to choose three different hunters whose positions do not lie on one straight line. If such a triple exists, we print Yes and their indices.
We are given (N) distinct words. Every word is an anagram of every other word, and no letter occurs twice inside a word. We want to choose as many words as possible so that no two chosen words can be obtained from one another by swapping exactly one pair of positions.
Each star has a fixed position (X, Y) and a brightness B. Bernie may rotate the entire picture, and then the printer scans from top to bottom. After rotation, a star with a larger transformed Y coordinate is printed earlier.
For each month, the farmer's wealth changes by the corresponding value in A. After adding that month's income, the wealth is immediately forced back into the interval [L, U]: values above U become U, and values below L become L.
We have a lowercase string, and we want to count its subsequences whose chosen characters are all different. A subsequence is determined by the positions we choose, so choosing the first a from aab and choosing the second a are different subsequences, even though both produce…
We start with an integer (A) and want to turn it into (B). At any moment, we may increase the current value by one, or divide it by two when the current value is even. Every operation costs one, so the task is to find the minimum number of operations.
We have an array of length (n), and every value from (1) through (k) occurs somewhere in it. We need to delete some elements while preserving the original order, leaving exactly one copy of every value from (1) through (k).
We have 2n distinct cards, numbered from 1 through 2n. They are randomly divided into n pairs, with each pair going to one guest. A guest's score is the sum of the two cards in their pair. We need the probability that exactly one guest has the maximum score.
For every contiguous segment [L, R], there are two ways to evaluate it. Starting at L, repeatedly take the remainder by the next array element: a[L] % a[L+1] % ... % a[R]. Starting at R, do the same thing in the opposite direction: a[R] % a[R-1] % ... % a[L].
For an integer (x), crossing out digits means deleting some positions from its decimal representation while keeping all remaining digits in their original order. A number is disliked if some positive Fibonacci number can be obtained this way.