brain
tamnd's digital brain — notes, problems, research
43815 notes
We have an even number of indexed stones, and each stone carries an integer between 0 and 1000. We must partition all stones into pairs.
The warehouses and roads form a tree, so between any two warehouses there is exactly one route. A truck has battery capacity T, and it may recharge whenever Sam stops.
We have an (N times N) chessboard represented by (N) strings. A is an opponent piece, K is our king, and - is an empty square where a pawn may potentially be placed. Pawns move upward, meaning a pawn at row (r+1), column (c) attacks the two squares ((r,c-1)) and ((r,c+1)).
We have a strip of cells, each colored either R or B. A move can be made on any current strip whose two endpoint colors are different. The move chooses a cut between two cells and splits that strip into two nonempty strips.
The grid is a graph whose vertices are all non-wall cells, with edges between cells sharing a side. The friends start at s and need to reach f. Every horizontal move changes the temperature by -1, regardless of whether the move goes left or right.
We have a rectangular sheet divided into n × m unit cells. Bill cuts only along grid lines and follows a fixed right-turning spiral.
We have an array of (n) positive integers. We may choose any subset of its elements, and the subset is considered good when the greatest common divisor of all chosen values is greater than (1). The task is to find the maximum possible number of elements in such a subset.
We have a simple undirected graph with up to 300,000 vertices and 300,000 edges. A diamond consists of two different triangles that use the same edge. If an edge has several vertices connected to both of its endpoints, every pair of those common neighbors forms one diamond.
We have a dictionary of known words. For every query, one dictionary entry is chosen as the secret word (S), and an integer (K) determines how many unsuccessful guesses the second player may make before another letter of (S) is revealed.
For each candidate, we know five integer statistics: height, wingspan, points per game, rebounds per game, and assists per game. Each statistic has its own expected interval, and the candidate is judged by where every value lies relative to that interval.
The spectator secretly chooses two numbers, say (a) and (b). The trick constructs a value from them by first increasing both numbers by one, multiplying the results, then subtracting (a), subtracting (b), and finally subtracting (ab).
We have an (n times m) grid. Every cell contains an object with an integer size (a{ij}). We need to visit every cell exactly once, moving only between side-adjacent cells, and the sequence of object sizes along the route must be nondecreasing.
Think of every non-burnt cell as a vertex of a graph. Two vertices are connected when their cells share a side. The statement guarantees that this graph is connected.
Каждый этаж башни требует ровно один килограмм железа и один килограмм дерева.
We track a snail that starts at depth n, where depth 0 means it has reached the ground. During each day it climbs a meters. If that climb reaches or passes the ground, the snail escapes immediately and the process ends.
For each testcase, we receive one nonempty string containing only English letters. The required encoding applies three transformations in the order described by the problem: change every letter to the opposite case, reverse the entire string, and apply ROT13 while preserving…
We have a rectangular table of width m and height n. The ball starts at the interior point (x0, y0) and must reach (x1, y1). It always travels along straight segments, reflecting from a wall with equal incident and reflection angles.
We need to make exactly d dollars of change. The available coin denominations are every integer from a through some upper bound b, inclusive, and we may use any denomination any number of times.
We repeatedly roll a fair die with k faces. A successful roll is one that shows 1, and the game ends as soon as we have seen n successful rolls consecutively.
We have m companies and n future days. For every company, we know its stock price on every day. The input stores one company per row, so each row contains that company's prices from day 1 through day n. We start with d pounds before the first known day.
We have two programs written in a tiny language with three kinds of statements: defining a variable, reading a variable, printing a variable, and assigning the sum of two variables to another variable.
We maintain an integer array (A) of length (n), initially filled with zeroes. A type 2 operation adds an arithmetic progression to one contiguous interval. For an operation ((l,r,a,b)), position (i) receives [ a+b(i-l).
For each test case, we need to print an array of exactly (n) integers. Every value must lie in the interval ([0,m]), the ordinary sum of all values must be (s), and their bitwise XOR must be (x). If no such array exists, we print (-1).
We have two strings a and b of the same length. We must choose two different positions and swap those positions in both strings simultaneously. The goal is to make the resulting a lexicographically larger than the resulting b.
There are n lottery tickets numbered from 1 to n. Exactly m of them are lucky, and their positions are given in the input. Miamiao chooses one interval [l, r], with every one of the n(n+1)/2 possible intervals equally likely, and buys every ticket in that interval.
We have (N) identical circular lighting regions. Their centers lie on one straight street, with consecutive centers exactly (L) units apart, and every circle has radius (R). The task is to compute the area covered by at least one light.
We have a screen of width (W) and height (H), and at most ten rectangular windows. The coordinate system is slightly unusual: the first coordinate increases downward and the second increases to the right.
We have gifts numbered from 1 to n. A child may choose any subset of them, with one restriction: whenever the child takes gift x, they cannot also take gift 2x. The value of a chosen set is the sum of all selected gift numbers, and we need the maximum possible value.
We are given two integers a and b generated from two unknown primes p and q: [ a=(pq)oplus(p+q), ] [ b=(pq)oplus(p-q). ] The task is to recover the original ordered pair (p, q).
Think of every unit square as a vertical column whose bottom is at height h[i][j] and whose horizontal area is exactly 1. A common horizontal water surface is chosen, and a column contributes water only when its bottom lies below that surface.
We have an array of n positive integers. Every pair of indices l <= r defines one contiguous subarray, and its value is the sum of all elements from l through r.
We need to evaluate several chemical formulas and compute their relative molecular masses. A formula is a sequence of element symbols, where an element symbol consists of one uppercase letter and possibly one lowercase letter.
Each text has already been converted into a frequency vector. So the string processing part is completely gone. For one test case, we only need to examine a collection of (n) vectors, each having (m) integer coordinates, and decide whether those vectors are linearly dependent.
We have one reference string s. Every non-empty subsequence of s is considered a valid spell. For each input string a, some original spell has been followed by an arbitrary suffix, so the useful part of a is exactly its longest prefix that can still be embedded as a…
This is an introductory input/output problem. The program receives one line containing the rules of a competition, and its only job is to print a fixed heading followed by exactly the same line of rules.
The problem asks us to compute the mechanical advantage of several levers. For each test case, we are given two positive lengths, A and B, representing the two sides of the lever. The mechanical advantage is the ratio of these lengths, so the required value is A / B.
We have an (ntimes m) chessboard whose cell ((i,j)) has value (+1) when (i+j) is even and (-1) otherwise. A valid path consists of exactly (n) north steps and (m) east steps, starting at the bottom-left corner and ending at the top-right corner.
We have a directed graph with up to 2000 vertices and 4000 directed edges. We must count ordered pairs of paths (P1, P2). A path may be empty and may repeat vertices, but repetition is only possible through a directed cycle.
Edit We have a 6 by 6 board containing at most 10 vehicles. Every vehicle occupies either two consecutive cells, as a car, or three consecutive cells, as a truck. A vehicle has a fixed orientation, horizontal or vertical, and can slide only along that orientation.
Each shop is a vertex of a tree, and shop (i) sells exactly one fence segment of length (ai). Choosing two shops (x) and (y) means taking every segment on the unique tree path between them.
We have two groups of m engineers, algorithm engineers and software engineers. Each engineer is located in one of n buildings and has an individual assignment cost.
Each object is one of three convex solids: a cube, a sphere, or a regular tetrahedron. Its size, orientation, and horizontal release position are given. The objects are released one at a time, and each one falls only vertically.
We have an odd-length array of distinct integers. An operation chooses three consecutive current elements and replaces those three elements by their median, so the array becomes shorter by two.
We maintain a changing dictionary of words. An insertion assigns the word the index of that query, and a deletion refers back to that insertion index. For a type 3 query, we are given a string X and need to find an active dictionary word that starts with X.
The night can be viewed as an array of N positions. Position i stores the drink Beza consumed during the i-th hour. The bar provides M drink names, and each name has an associated alcohol volume. A type 1 query changes one array position to another drink.
We have a weighted tree of cities. Because the graph is a tree, between every pair of cities there is exactly one path, so that path is automatically the shortest path.
Josya is the first participant in the input. Every athlete runs five identical laps and shoots at twenty targets in total. Ten targets are shot from the prone position and ten from the standing position. A hit costs no extra time, while every miss adds exactly 60 seconds.
We are given one non-negative integer n, with 1 <= n <= 10^18. Instead of ordinary multiplication, we are asked to use bitwise OR as the operation that combines two numbers.
We have n cockroaches, and each cockroach has an m digit number written on its back. Some digits are known, while every ? can independently be replaced by any digit from 0 to 9. Leading zeroes are allowed.
We have an array of positive values a[1..n]. Two players process it from left to right. On each turn, the current player may discard any number of still-unused elements from the front, then takes the next element.
There are two kinds of mutable state in the problem, and separating them is the key to the whole solution. The cache has n byte positions and starts entirely at zero. Separately, there are m source arrays.
The operation in this problem is ordinary decimal multiplication with one crucial change: whenever several products land in the same decimal position, their sum is taken modulo 10, so no carry ever moves to the next position.
The input is a rectangular drawing of an orthogonal maze after a 45 degree rotation. Each non-dot character represents one diagonal wall segment inside its input cell.
Each star is described by three values. Its maximum contribution is (Ti), it loses (si) units of contribution per radian of angular misalignment, and its preferred direction is (ai).
We have a collection of (N) distinct words. Every word uses exactly the same set of letters, so each word is simply a different permutation of the same letters. No letter appears twice inside one word.
We have a set of at most 2000 points in the plane, with no three points on one line. A windmill consists of a rotating line and one point that currently acts as its pivot. The line rotates clockwise.
Each pulse travels along exactly one wire, either horizontally or vertically. A horizontal pulse on wire a starts at the left edge at time t, while a vertical pulse on wire a starts at the bottom edge at the same kind of reference time.
The cities and roads form a weighted tree. Each city (i) has a tax value (ti), and the cost of sending a ticket from city (u) to city (v) is [ (tu+tv)d(u,v), ] where (d(u,v)) is the total road toll along the unique path between the two cities.
We have a string S describing citizens at positions (2,4,6,ldots,2N). A character H means the polynomial must be positive at that position, while A means it must be negative. We need a polynomial with integer coefficients and integer roots.
We have an array of distinct plant heights, indexed from left to right. A grasshopper starts at some index and looks either left or right. It jumps to the first index in that direction whose height is strictly larger than the height of the plant where it currently stands.
The trail contains N viewpoints in the order encountered while walking toward the mountain peak. Their altitudes form a non-decreasing array, so moving forward never requires going downhill. The couple may choose any viewpoint as their starting point.
The grid has N rows and M columns, with every cell initially marked either G or B. Javasar wants to take a square region and have every cell in that square be good when he visits it. The useful part of the route is that he crosses the kingdom one complete row at a time.
Think of every mailing list as a vertex in a directed graph. When mailing list i contains mailing list j, draw an edge from i to j. Client emails are terminal vertices.
At every decision point, Catelyn has a permanent score C and a temporary turn total X. Hoster has permanent score H. Catelyn must choose between banking the current turn total or rolling the die again.
The city name is a string C. A picture can capture any contiguous section of C, so every substring of C is a possible picture. We may arrange the pictures in any order and concatenate their contents to obtain a friend's name.
A sculpture base can be represented by an array of positive integers [ a1,a2,ldots,aS, ] where (ai) is the number of blocks in the (i)-th stack. We need exactly (S) stacks and exactly (B) blocks, so [ a1+a2+cdots+aS=B, qquad aigeq 1. ] The order of the stacks matters.
We have a set of vegetable plants represented by points in the plane. The desired house is a square whose center is fixed at the origin, but its orientation is completely free. A plant may lie on the boundary of the square, but it cannot lie strictly inside it.
We have n distinct points in the plane, with no three on the same line. A windmill consists of a line and a current pivot point on that line. The line rotates clockwise around the pivot until it first reaches another point, which becomes the new pivot.
We are given a finite alphabet consisting of distinct lowercase letters, already written in alphabetical order, and a query string whose characters all belong to that alphabet.
We have (n) positions in an array, but the values assigned to those positions are not fixed. For each attempt, we receive (n) values and may permute them however we want. There are (q) fixed intervals on the array.
We have a changing set of fairies. Initially there are n fairies, numbered from 1 through n, and fairy i has an integer sociability value a[i]. During the observation there are q events. A type 1 event adds a new fairy.
The input is one string containing only lowercase letters and the three structural characters <, and /. We may arbitrarily permute all characters, but we cannot change their multiplicities. A valid result is a sequence of XML-like tags.
У нас есть дерево из n комнат. В каждой комнате находится один эльф с силой w[i].
We have a sequence of rooms numbered from 1 to (N). Room (N) is the destination and contains no coins. From room (i), Diego may jump to any later room whose index is at most (i+ki). When he visits a room (i<N), he collects its (ci) coins.
The input describes a maze whose walls are drawn diagonally. Each character position is a small square in the ASCII representation. A dot means that square contains no wall. A slash or backslash is a diagonal wall segment inside that square.
The operation in this problem looks like ordinary multiplication, except that every addition performed inside the multiplication discards carries.
We have a cyclic array of n candles. Each position contains one of three colors, R, Y, or B. A move may recolor position i, but only when the two neighboring positions, i - 1 and i + 1, currently have different colors. The new color of position i can be chosen arbitrarily.
The fabric is a rectangular grid of cells. Every cell marked X has to receive a cross on the front side, meaning both diagonals of that cell must be stitched.
We have tickets numbered from 1 through (N), arranged in increasing order on a circle. Diego starts at ticket (S). From the current ticket, the process moves exactly (K) surviving tickets to the right and removes the ticket where it lands.
We have a sorted tax table. Each row contains a horsepower boundary bi and a tax rate ti. The first boundary is always zero, and the boundaries strictly increase.
Think of every grid cell as a vertex of a directed graph. Two cells sharing a side are candidates for an edge, but a cell refuses to move in the direction written on it.
We have a sequence (X) of (n) integers. Every element is between (1) and (k), and every value from (1) through (k) occurs somewhere in the sequence. We need to delete some elements while preserving the relative order of everything that remains.
We have a rooted tree. Every vertex has an integer label. A jumping path is a sequence of vertices taken strictly downward through the tree, where every earlier vertex is an ancestor of every later vertex.
We have (N) stars around Earth. For each star (i), three values describe its contribution to the spaceship's travel distance.
A permutation of size n rearranges the numbers 1,…,n so that every number appears exactly once. Position i is a fixed point when the value placed there is also i.
The problem describes a sequence of stone piles, one for each animal. An animal starts with some number of stones. Then, in each round, a number k is announced.
We have an array of (n) nonnegative integers (a1,a2,ldots,an). We need the sum of the products of every three distinct elements, where the indices must satisfy (i<j<k): [ sum{1le i<j<kle n} ai aj ak.
Searching the web
We have (n) physical cubes. Each cube can display any digit that appears on one of its six faces, but a cube can display only one digit at a time. To build a number, Aurora chooses as many cubes as the number has digits and assigns one distinct cube to every digit position.
We have an ordered sequence of (n) lumberjacks. Lumberjack (i) works on one interval ([li,ri]), and on that interval he lowers the wall by exactly half a meter.
We have two positive integers, a and b, given as decimal strings, and we consider every integer from a through b. We multiply all of them together, then repeatedly replace the resulting number by the sum of its decimal digits until only one digit remains.
We have a row of (n) skyscrapers, and their heights form a permutation of (1,2,ldots,n). A valid jump uses three skyscrapers in increasing position order whose heights are also strictly increasing.
We have an undirected multigraph with (n) vertices and (m) edges, together with exactly (s) tokens. We choose a nonnegative integer (av) for every vertex (v), where (av) is the number of tokens placed there and the total is exactly (s). An edge ((u,v)) has capacity (min(au,av)).
We have an array a describing the difficulties of problems published on consecutive days. We need to choose three indices i < j < k such that the middle difficulty is exactly halfway between the other two: [ aj-ai=ak-aj. ] Rearranging gives [ ai+ak=2aj.
The hill can be viewed as a directed acyclic graph whose vertices are the spots (1,ldots,n). Every trail goes from a smaller index to a larger index, so the vertex numbering itself gives a topological order.
We have an array of transactions (a1,a2,ldots,an), where transaction (i) contains (ai) queries. We must partition this array into consecutive groups.
We have an integer array a of length n, and we want to transform it into a target array b. The only instructions we are allowed to print are two special foreach loops.
The railroad network is a tree. Each city is a vertex, each railroad is an edge, and traveling across one edge takes one hour. A subset of the vertices contains the cities where the teams are located.
The original loans do not matter individually once we know each person's net position. For every loan a b c, person a has given away c, while person b has received c.
There are (N-1) legal cutting positions inside a chocolate bar of length (L). Adding the two endpoints (0) and (L), we have (N+1) positions that describe (N) elementary pieces. We must choose exactly three of the interior positions, producing four contiguous pieces.