brain
tamnd's digital brain — notes, problems, research
43815 notes
The task is ordinary matrix multiplication. The input describes two rectangular matrices, m1 and m2. The first four integers give the width and height of the two matrices, in that order. The rows of m1 are provided first, followed immediately by all rows of m2.
The task is to approximate sin(x) using exactly n terms of its Maclaurin, or Taylor-at-zero, series. The input consists of the number n of terms followed by a real number x, where x is measured in radians.
We have a collection of uniquely named houses. Each house has two integer coordinates: its street number and its house number. One of the houses is designated as the reference house, and we must print the name of the other house that is closest to it.
We receive exactly nine binary digits. The first digit is a parity bit, while the remaining eight digits form the transmitted byte.
The task is a direct application of the unit circle. The input is one integer angle measured in degrees, between 0 and 359 inclusive. Imagine the ray obtained by rotating the positive x-axis counterclockwise by that angle.
Despite the name, this problem does not require constructing or analyzing a triangle. The task is simply to evaluate one trigonometric function for a supplied floating-point argument.
The grid is an (n times n) square board. Some cells contain gold, marked by X, and every other cell is empty, marked by .. From any cell, movement is allowed only horizontally or vertically, so moving to a neighboring cell costs exactly one step. Diagonal movement is forbidden.
A positive integer is called cheesy when it is divisible by the sum of its decimal digits. For example, the digits of 360 add up to 9, and 360 % 9 == 0, so 360 is cheesy. For 87, the digit sum is 15, but 87 % 15 != 0, so it is not cheesy.
The input describes a student's performance across several independent problem sets. Each line has the form a/b, where a is the number of questions answered correctly and b is the total number of questions in that set.
The world is a fixed 20 by 20 grid of Minecraft chunks. Every cell is either a known Taiga (T), Desert (D), Forest (F), or unexplored (.). At least one Taiga cell is already known, and the actual world contains exactly one Taiga biome.
The board is an n×m rectangle whose cells contain one of three symbols. is an alive cell, . is already dead, and X is a barrier. Every turn uses the current board and changes cells simultaneously. A non-barrier cell, whether or ., becomes .
The task is a direct three-dimensional geometry calculation. The spaceship has one fixed position (X, Y, Z), and the radar reports n alien positions.
The problem works with RGB colors. A color is represented by three integers, R, G, and B, each between 0 and 255. We are given one such triple and must identify which of four named colors it represents: red, green, blue, or yellow.
We have a collection of stone cubes and want to divide all of them into distinct pyramids. A high pyramid with base side length (n) uses square layers of side lengths (n,n-1,ldots,1), while a low pyramid uses (n,n-2,n-4,ldots).
We have n lanterns placed at strictly increasing integer coordinates x[0], x[1], ..., x[n-1]. We may choose any subset of them to leave switched on.
We have an array of (n) integers, and every contiguous subarray contributes according to the sign of its product. For each pair of endpoints (l le r), the product of (al,a{l+1},ldots,ar) is either negative, zero, or positive.
After a good contest, your rating is some positive integer n, and this rating is high enough to put you in Division 1. Codeforces considers a rating of at least 1900 to be Division 1. After every subsequent contest, your rating decreases by exactly 50.
The task is a small output-construction problem. We are given one integer n, which specifies the size of every part of a capital letter H. Each vertical leg contains n characters, and the horizontal bar has the same length as the distance between the two legs.
The train network can be modeled as an undirected graph. Every city is a vertex, and every train line is an undirected edge because the line can be traveled in either direction.
The task is to symbolically differentiate a polynomial written as a single line of text. A polynomial is made of terms such as 5x^5, x, 8x^2, or 10, and neighboring terms are separated by either + or -. The first term is guaranteed not to be a constant.
The string consists of lowercase letters and spaces. Its fun-ness is the number of characters that are currently f, u, or n. We may apply the same cyclic Caesar shift to every letter any number of times.
We have several candidate strings that could be written on a neon sign. Each string contains lowercase English letters and spaces. For every candidate, we care only about which different letters appear in it.
The task is to compute Euler's totient function φ(n). For a positive integer n, φ(n) counts the integers k from 1 through n whose greatest common divisor with n is exactly 1. Since gcd(n, n) = n, the value n itself contributes only when n = 1.
We have a ten-digit phone number, but some of its digits are unknown. The input is a string of exactly ten characters. A digit means that position of the phone number is already known, while x means that the digit at that position could be anything from 0 through 9.
The two spacelabs are located on planets in our solar system. The planets have a fixed order by distance from the Sun: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune.
The task asks us to decide whether a string contains a repeated substring that appears exactly the requested number of times consecutively. Unlike the previous pattern problem, the repeated section is allowed to begin at any position in the input string.
The problem models transposing a piece of music represented by note names. Each note belongs to the twelve-note chromatic scale, written using the names A, A, B, C, C, D, D, E, F, F, G, G. The first input value tells us how many semitones every note should move.
This is an interactive problem. There is no ordinary input containing the account balance. The interactor secretly chooses an initial balance (n), with (0 le n le 10^{18}), and our program has to discover enough information about it to transfer the entire balance away.
The robot moves in the plane, and its four commands are quarter-turns around one of two fixed radio towers. Commands 1 and 2 rotate the current point by 90 degrees clockwise or counterclockwise around the origin. Commands 3 and 4 do the same around the point ((1,0)).
We have an undirected graph whose vertices are cities and whose edges are roads. Sam starts in city s at time 0 and wants to reach city t as early as possible. Every road has its own repeating weather schedule. If a road has parameters a, b, and d, then its period is P = a + b.
We need to compute the sum of squares of the first (n+1) elements of a Fibonacci-like sequence. The sequence starts with two ones, so its first values are [ 1,1,2,3,5,8,ldots ] and every later value is the sum of the previous two.
Think about the last time each tree was attacked. If a tree is reset after year t, then it grows for exactly m - t years afterward, so its final height is m - t. Equivalently, define [ ti = m-hi. ] The value ti is the last reset time of tree i.
Think of every row and every column as a vertex of a bipartite graph. A cell containing 1 is an edge between its row vertex and its column vertex. The value ai tells us exactly how many edges must be incident to row i. The column degrees are completely under our control.
We have an undirected graph, and every edge must eventually point toward exactly one of its two endpoints. For a vertex whose value is specified as (ai), exactly (ai) incident edges must point into that vertex. A vertex with (ai=-1) has no restriction on its final in-degree.
We start with two values, x = 0 and a = 1, and want to make x equal to the given target n using as few operations as possible. The first operation adds the current a to x.
A star exists at every point whose two coordinates are integers. For each test case, we are given the two endpoints of a straight line segment, and we need to count every integer-coordinate point that lies on that segment, including both endpoints.
We have an undirected graph with at most 50 cities. A road lets a horse move between its two endpoints in one step, and a road may also be a self-loop. For a fixed city v, we need to decide whether there exists a walk that starts at v, uses exactly k roads, and ends back at v.
We need to recover a positive rational number (x=p/q), where both (p) and (q) are at most (10^9). We cannot see (p) and (q) directly. Instead, for a chosen prime modulus (m), the judge gives the integer (r) in the range (0le r<m) satisfying [ requiv p q^{-1}pmod m.
We have two arrays, (a) and (b), both indexed from (1) to (n). For every possible greatest common divisor (k), we must find the largest absolute difference ( The (10^5) bound rules out anything close to quadratic.
We process one chronological sequence containing two kinds of events. A positive value means that this much money is added to the shared account. A negative value represents a borrowing request whose size is the absolute value of that number.
We have a row of (n) marbles, where each marble has one of at most 20 colors. We may swap neighboring marbles, and the goal is to make every color occupy one contiguous block. The blocks themselves may appear in any order.
We have a strictly convex polygon whose vertices are given counterclockwise and have integer coordinates. We need to draw one straight line that divides the polygon into two regions of exactly equal area.
There are two traffic-light countdowns, initially showing (A) and (B). After every second, both values decrease by one. We are interested only in moments when both counters are still positive, because as soon as one reaches zero, the red-light period ends.
We need to judge one round of Rock-Paper-Scissors-Lizard-Spock. The first input line is the move chosen by the first player, and the second line is the move chosen by the second player. Each move is one of Rock, Scissors, Paper, Lizard, or Spock.
The maze is an (N times M) grid. A cell is either free, occupied by a solid wall W, or occupied by a glass wall G. Ordinary movement is possible only between adjacent free cells. The outer border consists of solid walls, so every ray eventually reaches a solid wall.
For a given maximum word length (N), the dictionary contains every lowercase English string whose length is from (1) through (N). Words of the same length appear in lexicographic order, while all shorter words come first.
We are given one nonempty decimal string, with no leading zero. The string is not necessarily interpreted in base 10. We may choose a base (B), provided every digit appearing in the string is a valid digit in that base.
We start with a regular polygon containing (N) vertices and want to keep as few of those vertices as possible while making the selected vertices themselves form a regular polygon.
We are given a chronological log of a parliamentary session. Every Add x event means that party x introduces a new bill. The newly introduced bill immediately becomes the one being discussed, so the bill that was being discussed before it is suspended.
We have a collection of point satellites around the origin. Each satellite has an angular position, a distance from the origin, and a mass.
We are given two collections of (n) unoriented lines through the origin. Each line is represented by its two intersections with the unit sphere, so every collection contains (2n) unit vectors and every vector occurs together with its negation.
We have two strings s and t of the same length. Every position contains either a or b. One operation chooses any position in s and any position in t, then swaps the two characters.
We need to count integer triples (a,b,c) that form a Pythagorean triple and also satisfy an additional equation. The sides are ordered as 1≤a≤b≤c≤n, so c is the hypotenuse.
We are given a target string containing at most seven characters when spaces are ignored, followed by a dictionary of words.
The task is a base conversion problem. The first alien species writes integers using base (a), while the second uses base (b). We are given the two bases and a number (n) written using digits valid in base (a). We must print the same integer written in base (b).
The input describes the three vertices of a triangle in the Cartesian plane. Each vertex is given by an integer pair (x, y), and the three vertices may appear in any order. The task is to compute the triangle's area as a decimal value.
The task is to summarize the countries represented in a Zoom meeting. There are (n) attendees, and each attendee contributes one country name. We need to count how many attendees belong to each distinct country, then order the countries by decreasing attendee count.
The tree starts with exactly one branch. Suppose there are currently (b) branches. During the next day, the tree creates (n cdot b) new branches, so the total becomes [ b+n b=(n+1)b. ] The same value of (n) is used every day, and (n1).
A string is called majestic when every character is immediately followed by the next character in the alphabet. The alphabet is circular, so after z comes a.
We have two hotel breakfast menus. Each menu is represented by a list of food item names. The task is to find the food items that appear on both menus, then print how many such items there are followed by the common items in alphabetical order.
We receive a sequence of integers one at a time. After each integer arrives, it must be inserted into a list that is kept in nondecreasing order. The required output is not just the final sorted sequence. After the first value, we print the one-element sorted list.
The problem asks us to examine one positive integer (n). We need to add up every positive divisor of (n) except (n) itself. If that sum equals (n), then (n) is a perfect number.
We are given a collection of lowercase words and must print the same words in reverse alphabetical order. In other words, the word that would appear last in ordinary dictionary order must be printed first, and the word that would appear first must be printed last.
The task is to decide whether the given string is an "alarming string". A string has this property exactly when the character a appears three times in it. All other characters, including spaces when they occur in the input, are irrelevant.
The task is deliberately simple. We receive one string, representing a line of text, and must decide whether that line should be considered a question. The definition is purely syntactic: the final character of the string must be ?. If it is, we print YES; otherwise we print NO.
We need to numerically approximate the area under a user-supplied function (f(x)) on the interval from (0) to (C).
We have a rectangular hall represented by an n × m grid. The grid contains empty cells, diagonal mirrors represented by / or , and special cells. A laser enters the hall from below at column x, so its initial direction is upward.
We are given one expression containing at least two positive fractions, with + between every pair. Each fraction has an integer numerator and denominator. The task is to evaluate the entire sum exactly, then print the result in lowest terms.
The task is to count how many ways a partially filled 4×4 grid can be completed into a Latin square. Every cell must contain a number from 1 through 4, and each number must occur exactly once in every row and exactly once in every column.
We have a subway network described line by line. Each subway line is given as an ordered sequence of station names, and a station is a transfer station if it belongs to at least two distinct subway lines. The order of stations inside a line does not affect the answer.
We receive three musical notes that form a major triad. The notes may be written in any order, and a note can use either sharp notation such as C or flat notation such as Df. We need to determine which of the three notes is the root.
The race gives us a fixed observation point at mile m and a finish line at mile k. For every biker, we know the time in seconds when they passed the observation point and their speed in miles per hour at that moment.
The task is to encode a lowercase string using an affine cipher. The two integers a and b define the cipher. For every letter, we first convert a to z into the numbers 0 through 25, apply [ y=(a x+b)bmod 26, ] and convert y back to a lowercase letter. Spaces are copied unchanged.
We have one misspelled word w and a dictionary containing n candidate words. For every dictionary word s, we compare every character of w with every character of s. A pair contributes one match exactly when the two characters are equal. If mat / (a b).
We are given one positive fraction written as a/b. The numerator a does not have to be smaller than the denominator b, so improper fractions such as 72/48 are valid.
Valera has n books arranged in a fixed order, and he has only t minutes available for reading. If he starts at book i, he must read book i, then i+1, then i+2, and so on. He cannot skip a book, and he cannot start a book unless he has enough remaining time to finish it.
A string is called diverse when every character has a different character immediately after it. In other words, for every position except the last one, the character at that position must not equal the character at the next position. The input contains one string with no spaces.
The task is to execute a tiny custom programming language. The input describes a sequence of source-code lines, and our program has to behave as if those lines were executed in order. The language has three kinds of statements: variable declarations, assignments, and printing.
We are given a plaintext sentence on the first input line and a keyword on the second line. The task is to encrypt the sentence with the classical Vigenère cipher.
You are flying toward one of several airports. Each airport has a number of free runway spaces, a distance from your current position, and a direction in which the airplane must fly to reach it.
The task is a small text-parsing and arithmetic problem. We are given one sentence describing a length, such as I am 1.5 meters, how many feet am I. The number and its original unit appear immediately before the comma.
The problem asks us to perform one of two inverse text substitutions. We are given a message, a single-character key, and a word key. The single character is guaranteed not to appear anywhere inside the key word.
The grid is a rectangular hall containing empty tiles and diagonal mirrors. The laser enters from the bottom at column x and initially travels upward. Whenever it reaches an empty tile, that tile has to be marked according to the direction in which the laser passes through it.
We have an (N times N) chessboard and want to place exactly (N) queens so that no two queens can attack each other. A queen attacks horizontally, vertically, and diagonally, so every pair of queens must occupy different rows, different columns, and different diagonals.
We have an n × m maze. Each cell contains a single digit from 0 to 9, representing the radiation level of that cell. We start at the upper-left cell and need to reach the bottom row. Movement is allowed between cells sharing a side, so we may move up, down, left, or right.
We are given two strings of capital letters. The first string is the text that actually appears on the eye chart, while the second is the text that was read. The strings have the same length, so every position in the first string corresponds to exactly one position in the second.
The input is one line containing a sequence such as 3 + 4 3 - 6 / 3 3. Every number occupies one token and consists of exactly one digit, with exactly one space between consecutive tokens. The first and last tokens are numbers.
We have an (n times n) square grid representing a metropolis. Each cell contains a digit from 0 to 9, which is the height of the building in that cell.
We have n positive resistors connected in parallel. If two resistors have resistances a and b, their equivalent resistance is [ R=frac{ab}{a+b}.
The problem gives us a collection of cars. Each car has a name, a fuel efficiency measured in miles per gallon, and a maximum speed. For every car, we define its score as [ text{score} = text{MPG} times text{top speed}. ] We must print all cars in increasing order of this score.
The problem asks whether a spherical balloon can grow large enough to reach a required volume (v1) while remaining completely inside a cube-shaped box whose volume is (v2). The two given numbers are volumes, not the sphere's radius or the cube's side length.
We are given an inclusive integer interval from x to y. Among all numbers in that interval, we need to find the largest one that is a power of two. If the interval contains no power of two, we print -1. The answer must fit in a signed 32-bit integer.
We are given a playlist of songs. Each song has a title and a duration written as MM:SS, where the minutes and seconds use two digits. The task is to print the title of the longest song.
The task is a direct classification of a computer's hard-drive capacity. The input is a string such as 300GB, where the numeric part is the capacity in gigabytes and the final GB is a fixed suffix.
The problem models the process of winding a model airplane's rubber band. One complete turn of the crank winder produces a fixed number of winds in the rubber band.
An isotope contains two kinds of particles relevant to this problem: protons and neutrons. Its mass number counts both of them, so [ m = p + n, ] where (p) is the number of protons, (n) is the number of neutrons, and (m) is the mass number.
The task is deliberately simple. The input consists of one line of text, and the line may contain arbitrary ASCII characters. The required output is that exact line printed three times, with each copy on its own line.
The task is to decide whether a rectangular integer array has both kinds of mirror symmetry. Horizontal symmetry means a row must match the row at the same distance from the opposite edge.
The input is a sequence of integer-looking tokens, but those tokens are written in base 8 rather than the usual base 10. Each octal number represents one Unicode code point after being converted to its decimal value.
The task is to inspect one string and decide whether its beginning contains a repeated pattern. The pattern must start at position zero, must have length at least two, and must occur completely at least twice. Any characters after those two or more complete copies are irrelevant.