brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 102697071 - Days between two Dates

The task is to calculate how many calendar days separate two valid dates. Each date is written as a month name, a day number, and a year, for example June 21, 2019.

codeforcescompetitive-programming
CF 102697070 - Mersenne Primes

A Mersenne number has the form [ Mp = 2^p - 1. ] The input contains the exponent (p), and the task is to decide whether (Mp) is actually prime. The required output is the lowercase word true when it is prime and false otherwise.

codeforcescompetitive-programming
CF 102697059 - Multiply Characters

We are given one lowercase string. Most characters should remain exactly as they are, but three characters have special multiplicities. Every c must appear twice in the output, every h must appear five times, and every z must appear twelve times. Any other character appears once.

codeforcescompetitive-programming
CF 102697058 - Switch Case

The task is to transform one string by changing the case of every alphabetic character. An uppercase letter must become its lowercase counterpart, while a lowercase letter must become uppercase.

codeforcescompetitive-programming
CF 102697051 - The Convergence of Two Tetra-sided Polygons, Known as Rectangles

We are given two axis-aligned rectangles. Each rectangle is described by two opposite corners, so one line contains four integers x1 y1 x2 y2 for the first rectangle, and the next line contains the same information for the second rectangle.

codeforcescompetitive-programming
CF 102697050 - The Array Checker-inator!

We are given two integer arrays. Their lengths and their order do not necessarily have to match. The checker should answer YES when both arrays contain exactly the same distinct values, regardless of how many times each value appears and regardless of the order in which the…

codeforcescompetitive-programming
CF 102697042 - Number Code (Harder Version)

The problem gives a dictionary of words and several number strings. The encoding uses only six letters: o becomes 0, i becomes 1, e becomes 3, a becomes 4, s becomes 5, and t becomes 7.

codeforcescompetitive-programming
CF 102697027 - Money Sum

The task is much simpler than the title might suggest. We have made (n) payments during the year, and each payment is given as a positive integer representing its amount in cents. The required answer is the total amount spent, also in cents.

codeforcescompetitive-programming
CF 102437E - Похожие заказы

We have two strings of length (n). The string (s) describes the current stack of boxes, while (t) describes the previous stack. We may rotate (s) cyclically to the left by some (k), and then apply the same Caesar shift to every character.

codeforcescompetitive-programming
CF 102419B - Super Jaber

The city is a one dimensional array of buildings. Building i has floors from 0 through h[i]. Jaber starts at (i1, f1) and must reach (i2, f2). Inside a building, moving between consecutive floors costs one move.

codeforcescompetitive-programming
CF 102388F - Shopping

We have n coin denominations, and each denomination can be used any number of times. For a target amount m, we need to count how many different multisets of coins sum exactly to m. The order of the coins does not matter, so 2 + 3 and 3 + 2 represent the same way of making change.

codeforcescompetitive-programming
CF 102388A - Strange Base

We need to print the unique canonical representation of a positive integer (n) using powers of the golden ratio [ phi=frac{1+sqrt5}{2}. ] Each position contains either (0) or (1), and two neighboring positions can never both contain (1).

codeforcescompetitive-programming
CF 102386I - Персеантовка

We are given a sentence whose words may have had their internal letters rearranged. For every word, the first and last letters were kept fixed, while any permutation of the letters between them was allowed.

codeforcescompetitive-programming
CF 102386D - Артем в армии

There are exactly three tanks, numbered 1, 2, and 3, and Artem starts in tank k. Each command names two different tanks. The crews of those two tanks exchange their tanks, so Artem moves only when his current tank is one of the two mentioned in the command.

codeforcescompetitive-programming
CF 102375L - Ближайшие точки

We have an integer grid inside the rectangle with corners (0, 0) and (X, Y). Among all marked points, p1 is special. We need to count every grid point whose Euclidean distance to p1 is no larger than its distance to every other marked point.

codeforcescompetitive-programming
CF 102375C - Совпадения

There are exactly (N) rooms, numbered from (1) to (N), and exactly (N) participants. Participant (i) has passport number (ai).

codeforcescompetitive-programming
CF 102697081 - It's a Mess!

The library contains books, and each book is described by two words: the author's last name and the book's genre. The input gives the books in an arbitrary order.

codeforcescompetitive-programming
CF 102697080 - 1337 5p34k

The task is a character-by-character translation into a basic form of leet speak. The input is one string containing arbitrary text. For each lowercase letter that has a specified leet replacement, we substitute the corresponding digit.

codeforcescompetitive-programming
CF 102697079 - Over The Rainbow

The task is about measuring distance on a fixed circular color wheel. The wheel contains seven colors in this order: red - orange - yellow - green - blue-green - blue - purple - red For each test case, we receive two color names.

codeforcescompetitive-programming
CF 102697078 - Flatten The Curve

The simulation tracks the cumulative number of infected people in the United States. Let (N) be the current number of infected people, let (N{max}=328.2) million be the population at which the curve flattens, and let (a) be the infection rate for a particular test case.

codeforcescompetitive-programming
CF 102697077 - That Hertz!

The task is a direct application of the temperature-dependent speed of sound. For every test case, we are given the air temperature in degrees Celsius and the distance, in kilometers, from a speaker to the furthest edge of the crowd.

codeforcescompetitive-programming
CF 102697076 - Jar of Candies

The jar starts with n candies. After that, we are given the number of candies still present in the jar on each observed day, beginning with the first day on which candies were stolen. For every day, we need to determine how many candies disappeared since the previous observation.

codeforcescompetitive-programming
CF 102697075 - Shopping Spree

The store has three sections arranged in a fixed cycle: Produce, then Meat, then Dry Goods, and finally back to Produce. During one complete loop through the store, you can collect at most one item from each section.

codeforcescompetitive-programming
CF 102697074 - Infinity Gauntlet

This problem is much simpler than the title might suggest. The input contains a number of test cases, and each test case consists of one integer. For every integer, the Infinity Gauntlet's only relevant ability is to divide that number by two.

codeforcescompetitive-programming
CF 102697073 - It's A Me!...

The task is deliberately simple. The input is a sentence fragment, such as It's a me,, and the required output is that same text followed by the literal string Mario!. The original text must remain unchanged, including its punctuation and spaces.

codeforcescompetitive-programming
CF 102697072 - Tri-Angle

We are given exactly three points in the plane, representing the vertices of an isosceles triangle. The three input lines may appear in any order.

codeforcescompetitive-programming
CF 102697069 - Word Rotation

The task is to rotate every character of a lowercase word independently. For the character at position i, the input gives an integer shift k[i]. A positive shift moves the character forward through the alphabet, while a negative shift moves it backward.

codeforcescompetitive-programming
CF 102697068 - Relative Strength Index

We are given a sequence of (N) historical prices, in chronological order. For every pair of consecutive measurements, the price either rises, falls, or stays unchanged. The RSI calculation only cares about the rises and falls.

codeforcescompetitive-programming
CF 102697067 - Tangential Velocity

The problem describes an object moving around the center of a circle. We know the centripetal force acting on the object, its mass, and the radius of its circular path. From these three quantities, we need to calculate the object's tangential velocity.

codeforcescompetitive-programming
CF 102697066 - Neural Network Weight Count

A neural network is represented only by its layers. If two consecutive layers contain a and b nodes, every node in the first layer connects to every node in the second layer. Each such connection is one weight.

codeforcescompetitive-programming
CF 102697065 - Intersection of Two Lines

Each line is given in the form [ y = mx + b ] where (m) is its slope and (b) is its (y)-intercept. The input contains the two coefficients of the first line on one row and the two coefficients of the second line on the next row.

codeforcescompetitive-programming
CF 102697064 - Gas Cost

The task is to calculate the fuel expense of one car trip. The input gives three floating-point values: the car's fuel efficiency in miles per gallon, the distance driven in miles, and the price of one gallon of gasoline.

codeforcescompetitive-programming
CF 102697063 - Schwarzschild Radius

The task is a direct application of the Schwarzschild radius formula. We are given the mass (M) of an object, and we must calculate the radius of its event horizon using [ rs=frac{2GM}{c^2}.

codeforcescompetitive-programming
CF 102697062 - Delete Characters

The task is a direct string filtering problem. We have a string S, followed by a collection C containing the characters that must disappear.

codeforcescompetitive-programming
CF 102697061 - Half Winds

A compass can be divided into sixteen principal and intermediate directions. The four cardinal directions are North, East, South, and West, while the four diagonal directions are Northeast, Southeast, Southwest, and Northwest.

codeforcescompetitive-programming
CF 102697060 - Maximum Number

The task asks for the largest signed integer that can be represented using exactly (N) bits. For a signed integer representation, one bit is reserved for the sign, leaving (N-1) bits for the magnitude of the largest positive value. The maximum is consequently [ 2^{N-1}-1.

codeforcescompetitive-programming
CF 102697057 - Minecraft Prank

The task describes a house as a three-dimensional structure. Its vertical size is given first, and its foundation is then described by several rows containing X characters. Each X represents a block belonging to the foundation.

codeforcescompetitive-programming
CF 102697056 - Stopwatch issues

The stopwatch stores only a total number of elapsed seconds. We need to turn that single number into a human-readable duration using years, days, hours, minutes, and seconds. For this problem, one year is treated as 365 days.

codeforcescompetitive-programming
CF 102697055 - Train-ficiency

The station has four trains, and each train is described by its number of carts. A track can hold exactly 100 carts, so the task is to find the two trains whose lengths add up to 100.

codeforcescompetitive-programming
CF 102697054 - When is my meeting?

We receive two calendar dates. The first date represents today, and the second date represents the scheduled meeting. Each date is written as a month name, a day number, and a year, such as July 5, 2019. The task is to determine the number of days separating the two dates.

codeforcescompetitive-programming
CF 102697053 - Tic-Tac-Toe

We are given which player we control, either X or O, followed by the current 3 by 3 Tic-Tac-Toe board. An empty cell is represented by a space.

codeforcescompetitive-programming
CF 102697052 - Passing Notes

The note is a single line of text. The scrambling rule can be inferred from the example: every character of the original note appears in exactly the same order relative to the others, but the entire line is reversed. For example, the text abc def becomes fed cba.

codeforcescompetitive-programming
CF 102697049 - Decryption

We are given a composite integer (n). Every divisor of (n) greater than (1) must be placed exactly once around a circle. We are free to choose their initial cyclic order.

codeforcescompetitive-programming
CF 102697048 - Basic Math

The task is to evaluate a single arithmetic equation containing integers connected by addition and subtraction. The equation ends with an equals sign, and the required output keeps the original equation intact while appending its numerical result.

codeforcescompetitive-programming
CF 102697047 - Who will win

Two runners are in a 400 meter race. For each runner, the input gives their identifier, their constant speed in meters per second, and the distance they have already covered. The race continues with each runner maintaining the given speed.

codeforcescompetitive-programming
CF 102697046 - Binary Math

The task is to add two non-negative integers whose representations are given as binary strings. The first line contains one binary number, the second line contains another binary number, and the required output is their sum, also written in binary.

codeforcescompetitive-programming
CF 102697045 - Planet Omicron Persei VIII

The problem gives three physical quantities describing an object falling on Planet Omicron Persei VIII. The first value is the gravitational force (Fg) acting on a person, the second is that person's mass (M), and the third is the distance (D) through which the object falls.

codeforcescompetitive-programming
CF 102697044 - Yoda Translator

The task is deliberately simple. We receive one sentence as a single line, and the sentence contains an even number of words. We have to split the sequence of words into two equal halves, then place the second half before the first half.

codeforcescompetitive-programming
CF 102697043 - Low-Budget Flight Paths

We have a directed flight network. Each flight goes from one city to another and has a price. The team starts in Syracuse, must reach the competition city, and then must return to Syracuse. The total price of the complete round trip cannot exceed the given budget.

codeforcescompetitive-programming
CF 102697040 - Valid Sudoku

We are given a complete 9 by 9 Sudoku grid. Every cell contains an integer, and the task is to decide whether the grid obeys the three Sudoku uniqueness rules: a digit cannot appear twice in one row, twice in one column, or twice inside the same 3 by 3 box.

codeforcescompetitive-programming
CF 102697039 - Number Code (Easier Version)

The problem defines a fixed substitution code between six digits and six letters: 0 represents o, 1 represents i, 3 represents e, 4 represents a, 5 represents s, and 7 represents t. Each test case is a sequence of space-separated number strings.

codeforcescompetitive-programming
CF 102697038 - Unshuffle the Cards

The task is simply to restore a partially complete deck to its canonical sorted order. Each card has a rank and a suit. Ranks are ordered numerically, with ace considered higher than every other rank.

codeforcescompetitive-programming
CF 102697037 - Practice Katanas

The problem asks for the least common multiple, or LCM, of two positive integers a and b. The LCM is the smallest positive integer that is divisible by both numbers.

codeforcescompetitive-programming
CF 102697036 - Speed Limits

The problem maintains a database of states. For every state, the database stores its maximum allowed speed. After building this database, we receive several queries, where each query names one state. For every queried state, we must print the speed limit stored for that state.

codeforcescompetitive-programming
CF 102697035 - Distinct Numbers

We have a list containing n integers, and the task is to determine how many different values occur at least once. The positions of the values do not matter. For example, the list 2 2 3 5 6 contains the four distinct values 2, 3, 5, and 6, so the answer is 4.

codeforcescompetitive-programming
CF 102697033 - Free Throws

The task asks for the team's overall free throw percentage. There are (n) players, and for each player we know two counts: how many free throws they made and how many they attempted.

codeforcescompetitive-programming
CF 102697032 - Prison Break

The lock has (n) independent dials. For dial (i), the allowed values form every integer from its lower limit (Li) through its upper limit (Ri), inclusive. A complete lock combination chooses exactly one allowed value for every dial.

codeforcescompetitive-programming
CF 102697031 - 2001: A Space Odyssey

We are given one positive composite integer n. The task is to find the smallest divisor of n that is greater than 1. For example, the divisors of 2001 begin with 1, 3, 23, ..., so the required answer is 3.

codeforcescompetitive-programming
CF 102697030 - World Cup (Easier Version)

The team has played some number of matches in the group stage. The input gives three counts in the fixed order of wins, losses, and ties, with the values separated by hyphens. A win contributes 3 points, a tie contributes 1 point, and a loss contributes nothing.

codeforcescompetitive-programming
CF 102697025 - Write It, Do It

We are given a misspelled word s and a dictionary of candidate words. The spelling error has a specific structure: letters may have been replaced by other letters, but no letters were inserted or deleted. That means the intended word must have exactly the same length as s.

codeforcescompetitive-programming
CF 102452B - Binary Tree

We have a rooted binary tree with node 1 as its root. Alice and Bob alternately remove one subtree. A move is legal only when the removed subtree is a perfect full binary tree, meaning every internal node has exactly two children and all leaves are at the same depth.

codeforcescompetitive-programming
CF 102439A - Four minutes until BSUIR Open

We have a straight road from position 0 to the university at position (xn). Camera (i) is at position (xi), and when the car passes that point its speed must be at most (vi). The car starts at speed zero.

codeforcescompetitive-programming
CF 102439E - Small business

We have a bag of digit blocks, represented by a string s. Every block must be used exactly once to build two decimal integers. The two integers may be equal, zero is allowed, but neither number may contain leading zeroes. Both numbers must be at most (10^{18}).

codeforcescompetitive-programming
CF 102433F - Carny Magician

We need to arrange the numbers from (1) to (n) into a permutation. Position (i) is called fixed when the value placed there is also (i). Among all permutations with exactly (m) fixed positions, we must output the (k)-th one in lexicographic order.

codeforcescompetitive-programming
CF 102433C - Coloring Contention

We have a connected undirected graph whose vertices are numbered from 1 to (N). Alice assigns one of two colors to every edge. After seeing the coloring, Bob chooses a route from vertex 1 to vertex (N).

codeforcescompetitive-programming
CF 102428E - Eggfruit Cake

The cake border is a circular sequence of distinct fruits. We represent an eggfruit by E and a persimmon by P. A valid slice consists of a consecutive circular segment of fruits, contains at most S fruits, and must contain at least one eggfruit.

codeforcescompetitive-programming
CF 102428A - Algorithm Teaching

Each teacher knows a small set of algorithms. A student trained by that teacher can learn any non-empty subset of those algorithms. Two students can coexist in the final team exactly when neither student's learned set contains the other's learned set.

codeforcescompetitive-programming
CF 102426B - The Secret of Time

There is no input at all. We only need to print one positive integer (x) whose square is a 16 digit decimal number satisfying several digit conditions.

codeforcescompetitive-programming
CF 102426C - LytchenLovesJSON

The task is essentially to implement a small JSON interpreter. The input begins with one valid JSON document whose root is always an object. The document may contain nested objects, arrays, strings, numbers, booleans, and null.

codeforcescompetitive-programming
CF 102426H - 白学串

We have an array of positive integers. A query gives an interval [l, r], and asks whether we can choose any three elements from that interval that can be the side lengths of a non-degenerate triangle.

codeforcescompetitive-programming
CF 102426G - 伙伴系统

The system maintains free memory only through 11 counters. Counter i stores how many free blocks have size 2^i, where i ranges from 0 through 10.

codeforcescompetitive-programming
CF 102423B - Computer Cache

The cache is an array of n byte addresses, initially filled with zero. We also have m independent data pieces, where each piece is itself a byte array. A load operation copies an entire piece into a consecutive region of the cache, replacing whatever was there.

codeforcescompetitive-programming
CF 102419G - Large array

The array a is not given explicitly. It is an infinite-looking repetition of the shorter array b, truncated after n elements. If b = [b0, b1, ..., b(m-1)], then every block of m consecutive elements of a is another copy of b.

codeforcescompetitive-programming
CF 102419E - Geometry Problem

I can write the complete editorial, but the geometry figure is essential to deriving the formula. The statement only says “find the area of the grey area, in the figure,” and the figure is not included in the material you provided.

codeforcescompetitive-programming
CF 102419D - Xor the graph

We have an undirected graph, and every vertex already carries an integer smaller than (2^{20}). We may choose a subset of vertices and one XOR value (x), then replace every chosen value (ai) by (ai oplus x). The goal is to make the two endpoint values different on every edge.

codeforcescompetitive-programming
CF 102416A - Palindrome

We need to inspect a collection of positive integers and count how many have the same sequence of digits when read from left to right and from right to left.

codeforcescompetitive-programming
CF 102416E - Space guardians

We have at most 100 spherical protected regions in three-dimensional space. Starship (i) has center ((xi,yi,zi)) and radius (ri). We must choose some starships whose original spheres do not overlap. Touching at exactly one point is allowed.

codeforcescompetitive-programming
CF 102411K - King's Children

We have an (n times m) grid. Some cells contain distinct uppercase letters, each letter representing one child's castle, while every other cell is empty. The task is to replace every empty cell by the lowercase letter of the child whose rectangular province contains that cell.

codeforcescompetitive-programming
CF 102411B - Bad Treap

A treap is simultaneously a binary search tree by its key (x) and a min-heap by its priority (y). In this problem the priority is not random: for every integer key (x), it is fixed as [ y=sin(x).

codeforcescompetitive-programming
CF 102396E - Unique Solution

We are given a target vector (a) of length (n), where every coordinate is (-1), (0), or (1), and at least one coordinate is nonzero.

codeforcescompetitive-programming
CF 102396C - Jet Trains

Think of the cities as vertices of an undirected graph whose edges are the currently available train routes. Since routes are bidirectional, two cities can reach each other exactly when they belong to the same connected component of this graph.

codeforcescompetitive-programming
CF 102396G - Weight Overflow

We have up to 25 weights, and each weight may be placed on the first plate, the second plate, or left unused. The scale does not compare the ordinary sums. Instead, it reduces both plate sums modulo (m), and reports balance when those two residues are equal.

codeforcescompetitive-programming
CF 102391E - Dead Cacti Society

We start with a connected weighted cactus. Each original vertex (v) has a healing value (RVv), and each original edge (e) has a length (Le) and a healing value (REe). For every cycle, exactly one edge must be removed. Removing an edge (e={u,v}) does not simply delete it.

codeforcescompetitive-programming
CF 102391I - Minimum Diameter Spanning Tree

We need to choose exactly (N-1) edges from a connected weighted undirected graph so that every vertex is reachable and the resulting graph is a tree. Among all such spanning trees, we want one whose longest weighted path is as short as possible.

codeforcescompetitive-programming
CF 102391B - Bigger Sokoban 40k

This is an output-only constructive problem. There is no input at all. Our program only has to print one Sokoban board satisfying the geometric constraints and having the stronger property that every valid solution requires at least 40,000 player moves.

codeforcescompetitive-programming
CF 102386F - Кубик

На клетчатом поле движется обычный кубик. До начала движения на его шести гранях можно расставить числа от 1 до 6, каждое число ровно один раз.

codeforcescompetitive-programming
CF 102386E - Отложенные операции

We have a sequence of (n) days. On day (i), a homework assignment for subject (ai) appears. Dima may either spend the day doing all currently accumulated homework for one subject, or do nothing. Doing a subject clears every assignment of that subject received so far.

codeforcescompetitive-programming
CF 102386C - Найди отличия

We are given two rectangular character images of the same size. Each image is represented by n rows, each containing exactly m non-whitespace characters.

codeforcescompetitive-programming
CF 102375I - Составление задач

We have (P) participants and (T) available problems. Each input pair ((u,v)) says that participant (u) knows problem (v). A problem may be known by several participants, and a participant is unable to compete if they know at least one problem that was selected for the contest.

codeforcescompetitive-programming
CF 102375B - Большие перемены

We have (N) labeled cities and must build a connected undirected graph using exactly (N-1) distinct airline connections. Since a connected graph on (N) vertices with exactly (N-1) edges is a tree, the problem is really about labeled trees.

codeforcescompetitive-programming
CF 102373J - Transformations

We have two permutations of the same friends. The current line is a, and the required line is b. One reorganization chooses any nonempty set of friends, removes them from their current positions, reverses their relative order, and puts the reversed subsequence at the very front.

codeforcescompetitive-programming
CF 102373F - Они

We have an array a[1..n], where a[i] is the number of children at position i. The old Pennywise takes a prefix, positions 1 through l, while the modern Pennywise takes a suffix, positions r through n. The two segments must not overlap, so l < r.

codeforcescompetitive-programming
CF 102373E - Checkered Pattern

We have an (n times m) rectangular board whose cells are either black or white. After changing any number of cells, the black cells must form a nonempty connected graph, where cells sharing a side are adjacent, and that graph must contain no cycle.

codeforcescompetitive-programming
CF 102373A - Оно

We have two lowercase strings, s and t. We need to count nonempty substrings of s whose letters can be taken from t. The order of the letters does not matter, because we only care whether t contains enough copies of every character appearing in the chosen substring.

codeforcescompetitive-programming
CF 102348E - Painting The Fence

We have a row of (n) fence planks and (m) colors. Color (i) is available for exactly (ai) planks, and the values sum to (n), so every unit of paint must be used.

codeforcescompetitive-programming
CF 102346E - Exhibition of Clownfish

We have (N) tanks. Tank (i) contains (Mi) male clownfish and (Fi) female clownfish. The condition (Mi=0) or (Fi0) means every tank that currently has males also has at least one female. During one night, exactly one fish may be moved from one tank to another.

codeforcescompetitive-programming
CF 102346A - Artwork

The room is the rectangle with corners (0, 0) and (M, N). The thief needs a continuous path from the lower-left corner to the upper-right corner while staying strictly outside every sensor's detection disk.

codeforcescompetitive-programming
CF 102341B - Bulbasaur

The graph consists of (n) layers, each containing exactly (k) vertices. Edges only go from layer (i) to layer (i+1). A vine is a directed path, and two vines cannot share either a vertex or an edge.

codeforcescompetitive-programming
CF 102341C - Cloyster

We have an (n times n) grid, and every cell contains a distinct integer representing the shell size of the Cloyster there. The cell with the largest value is the leader. We cannot inspect the whole grid, because values are revealed only when we explicitly query a cell.

codeforcescompetitive-programming
CF 102341H - Hypno

We have a connected undirected graph with up to 200,000 intersections and 200,000 roads. We start at vertex 1 and want to reach vertex n. Traversing a road takes one minute, but every road hides one of two kinds of Hypno.

codeforcescompetitive-programming