brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 102697158 - Dot Product

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.

codeforcescompetitive-programming
CF 102697157 - Computing Sin

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.

codeforcescompetitive-programming
CF 102697156 - Closest Houses

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.

codeforcescompetitive-programming
CF 102697153 - Parity Checker

We receive exactly nine binary digits. The first digit is a parity bit, while the remaining eight digits form the transmitted byte.

codeforcescompetitive-programming
CF 102697152 - Unit Circle

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.

codeforcescompetitive-programming
CF 102697151 - Triangle Trigonometry

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.

codeforcescompetitive-programming
CF 102697146 - Gold Miner

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.

codeforcescompetitive-programming
CF 102697137 - Cheesy Numbers

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.

codeforcescompetitive-programming
CF 102697136 - Math Team

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.

codeforcescompetitive-programming
CF 102697130 - Minecraft Biome Finder

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.

codeforcescompetitive-programming
CF 102697129 - Conway's Game of Life

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 .

codeforcescompetitive-programming
CF 102697121 - Space Invaders

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.

codeforcescompetitive-programming
CF 102697118 - Colors

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.

codeforcescompetitive-programming
CF 102697110 - Pyramid

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).

codeforcescompetitive-programming
CF 102348H - Berland Prospect

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.

codeforcescompetitive-programming
CF 102348F - The Number of Products

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.

codeforcescompetitive-programming
CF 102697119 - Division One

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.

codeforcescompetitive-programming
CF 102697109 - H.

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.

codeforcescompetitive-programming
CF 102697104 - Trans Europe Express

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.

codeforcescompetitive-programming
CF 102697103 - Home Computer

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.

codeforcescompetitive-programming
CF 102697098 - It's More Fun To Compute

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.

codeforcescompetitive-programming
CF 102697097 - Neon Lights

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.

codeforcescompetitive-programming
CF 102697096 - Numbers

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.

codeforcescompetitive-programming
CF 102697092 - The Telephone Call

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.

codeforcescompetitive-programming
CF 102697091 - Spacelab

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.

codeforcescompetitive-programming
CF 102697085 - Pattern Two

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.

codeforcescompetitive-programming
CF 102697084 - Fine Tuned

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.

codeforcescompetitive-programming
CF 102437F - Быстрый перевод

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.

codeforcescompetitive-programming
CF 102437J - Delivery Robot

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)).

codeforcescompetitive-programming
CF 102437G - Regulated Shortest Path

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.

codeforcescompetitive-programming
CF 102437D - Квадраты Фибоначчи

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.

codeforcescompetitive-programming
CF 102419K - The Dragon and the Kingdom of Trees

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.

codeforcescompetitive-programming
CF 102419J - Jaber The policeman

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.

codeforcescompetitive-programming
CF 102419H - In-degree

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.

codeforcescompetitive-programming
CF 102419C - Two operations

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.

codeforcescompetitive-programming
CF 102388B - Stars

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.

codeforcescompetitive-programming
CF 102388E - Stables

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.

codeforcescompetitive-programming
CF 102354I - From Modular to Rational

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.

codeforcescompetitive-programming
CF 102354B - Yet Another Convolution

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.

codeforcescompetitive-programming
CF 102354C - Money Sharing

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.

codeforcescompetitive-programming
CF 102348C - Marbles

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.

codeforcescompetitive-programming
CF 102386K - Малыш и Карлсон

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.

codeforcescompetitive-programming
CF 102386H - Светофоры

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.

codeforcescompetitive-programming
CF 102386B - Турнир УрФУ

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.

codeforcescompetitive-programming
CF 102375J - Порталы

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.

codeforcescompetitive-programming
CF 102375H - ICPC

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.

codeforcescompetitive-programming
CF 102375G - Есть ли делитель?

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.

codeforcescompetitive-programming
CF 102375F - Правильный подмногоугольник

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.

codeforcescompetitive-programming
CF 102375E - Думский регламент

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.

codeforcescompetitive-programming
CF 102354H - Defying Gravity

We have a collection of point satellites around the origin. Each satellite has an angular position, a distance from the origin, and a mass.

codeforcescompetitive-programming
CF 102354F - Cosmic Crossroads

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.

codeforcescompetitive-programming
CF 102348G - Swap Letters

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.

codeforcescompetitive-programming
CF 102697149 - Pythagorean Theorem

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.

codeforcescompetitive-programming
CF 102697148 - Internet Anagram Server

We are given a target string containing at most seven characters when spaces are ignored, followed by a dictionary of words.

codeforcescompetitive-programming
CF 102697145 - Star Wars

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).

codeforcescompetitive-programming
CF 102697144 - Triangulation Rocks the Nation

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.

codeforcescompetitive-programming
CF 102697143 - Zoom Meeting

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.

codeforcescompetitive-programming
CF 102697142 - Hydra Tree

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).

codeforcescompetitive-programming
CF 102697141 - Majestic Strings

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.

codeforcescompetitive-programming
CF 102697140 - Continental Breakfast

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.

codeforcescompetitive-programming
CF 102697139 - Dynamic Sorting

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.

codeforcescompetitive-programming
CF 102697138 - Perfect Numbers

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.

codeforcescompetitive-programming
CF 102697135 - Anti-sort

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.

codeforcescompetitive-programming
CF 102697134 - Alarming String

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.

codeforcescompetitive-programming
CF 102697133 - Question-able Difficulty

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.

codeforcescompetitive-programming
CF 102697132 - Code RAMs

We need to numerically approximate the area under a user-supplied function (f(x)) on the interval from (0) to (C).

codeforcescompetitive-programming
CF 102697131 - The Mirrors Strike Back

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.

codeforcescompetitive-programming
CF 102697128 - What the Frac (Harder Version)

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.

codeforcescompetitive-programming
CF 102697127 - Latin Squares

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.

codeforcescompetitive-programming
CF 102697126 - Subway System

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.

codeforcescompetitive-programming
CF 102697125 - Chord Identification

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.

codeforcescompetitive-programming
CF 102697124 - Tour De France

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.

codeforcescompetitive-programming
CF 102697123 - Affine Cipher

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.

codeforcescompetitive-programming
CF 102697122 - Autocorrect

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).

codeforcescompetitive-programming
CF 102697120 - What the Frac (Easier Version)

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.

codeforcescompetitive-programming
CF 102697117 - Books

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.

codeforcescompetitive-programming
CF 102697116 - Diverse String

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.

codeforcescompetitive-programming
CF 102697115 - Pseudocode Compiler

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.

codeforcescompetitive-programming
CF 102697114 - Viginere Cipher

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.

codeforcescompetitive-programming
CF 102697113 - Airplane!

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.

codeforcescompetitive-programming
CF 102697112 - Unit Conversions

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.

codeforcescompetitive-programming
CF 102697111 - Word Subsitution

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.

codeforcescompetitive-programming
CF 102697108 - The Hall Of Mirrors

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.

codeforcescompetitive-programming
CF 102697107 - The Man Machine

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.

codeforcescompetitive-programming
CF 102697106 - Geiger Counter

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.

codeforcescompetitive-programming
CF 102697105 - Planet of Visions

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.

codeforcescompetitive-programming
CF 102697102 - Pocket Calculator

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.

codeforcescompetitive-programming
CF 102697101 - Metropolis

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.

codeforcescompetitive-programming
CF 102697100 - Ohm Sweet Ohm

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}.

codeforcescompetitive-programming
CF 102697099 - Autobahn

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.

codeforcescompetitive-programming
CF 102697095 - Techno Pop

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.

codeforcescompetitive-programming
CF 102697094 - Computer Love

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.

codeforcescompetitive-programming
CF 102697093 - Music Non Stop

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.

codeforcescompetitive-programming
CF 102697090 - Computer World

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.

codeforcescompetitive-programming
CF 102697089 - The Model

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.

codeforcescompetitive-programming
CF 102697088 - Radioactivity

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.

codeforcescompetitive-programming
CF 102697087 - The Robots

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.

codeforcescompetitive-programming
CF 102697086 - Symmetry

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.

codeforcescompetitive-programming
CF 102697083 - The Numbers Mason!

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.

codeforcescompetitive-programming
CF 102697082 - Patterns 1

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.

codeforcescompetitive-programming