brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 102367E - XOR Pairing

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.

codeforcescompetitive-programming
CF 102367D - Deliveries

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.

codeforcescompetitive-programming
CF 102367C - Pawn's Revenge

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

codeforcescompetitive-programming
CF 102373I - Звуки в подвале

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.

codeforcescompetitive-programming
CF 102373H - Escape from the Abundoned House

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.

codeforcescompetitive-programming
CF 102373G - Ножницы

We have a rectangular sheet divided into n × m unit cells. Bill cuts only along grid lines and follows a fixed right-turning spiral.

codeforcescompetitive-programming
CF 102373D - Good Subset

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.

codeforcescompetitive-programming
CF 102373C - Diamonds

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.

codeforcescompetitive-programming
CF 102375K - <<Контакт>> для двоих

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.

codeforcescompetitive-programming
CF 102375D - Драфт НБА

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.

codeforcescompetitive-programming
CF 102375A - Арифметическая магия

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

codeforcescompetitive-programming
CF 102386J - Катамари

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.

codeforcescompetitive-programming
CF 102386G - Уральские блинчики

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.

codeforcescompetitive-programming
CF 102386A - Строительство башни

Каждый этаж башни требует ровно один килограмм железа и один килограмм дерева.

codeforcescompetitive-programming
CF 102388G - Snails

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.

codeforcescompetitive-programming
CF 102388D - Secret Messages

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…

codeforcescompetitive-programming
CF 102388C - Snooker

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.

codeforcescompetitive-programming
CF 102416C - Quick coffee

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.

codeforcescompetitive-programming
CF 102416D - Calculated risk

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.

codeforcescompetitive-programming
CF 102416B - Efficient market

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.

codeforcescompetitive-programming
CF 102419L - Cheating detection.

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.

codeforcescompetitive-programming
CF 102419I - Another Query Problem

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

codeforcescompetitive-programming
CF 102419F - xor-sum

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

codeforcescompetitive-programming
CF 102419A - Two Strings

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.

codeforcescompetitive-programming
CF 102426L - Bonus quiz

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.

codeforcescompetitive-programming
CF 102426M - 长安街的华灯

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.

codeforcescompetitive-programming
CF 102426K - X-Window System

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.

codeforcescompetitive-programming
CF 102426J - 机房的圣诞礼物

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.

codeforcescompetitive-programming
CF 102426I - Integer Factorization

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

codeforcescompetitive-programming
CF 102426F - 浴缸

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.

codeforcescompetitive-programming
CF 102426E - 龙语魔法

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.

codeforcescompetitive-programming
CF 102426D - 元素周期表

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.

codeforcescompetitive-programming
CF 102426A - 自然语言处理

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.

codeforcescompetitive-programming
CF 102700M - Magic spells

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…

codeforcescompetitive-programming
CF 102697026 - Competition Rules

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.

codeforcescompetitive-programming
CF 102697018 - Machines

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.

codeforcescompetitive-programming
CF 102471B - Black and White

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.

codeforcescompetitive-programming
CF 102471L - Travel

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.

codeforcescompetitive-programming
CF 102460A - Rush Hour Puzzle

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.

codeforcescompetitive-programming
CF 102452C - Constructing Ranches

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.

codeforcescompetitive-programming
CF 102452K - Key Project

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.

codeforcescompetitive-programming
CF 102452F - Falling Objects

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.

codeforcescompetitive-programming
CF 102452E - Erasing Numbers

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.

codeforcescompetitive-programming
CF 102448C - Call from Mendes

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.

codeforcescompetitive-programming
CF 102448B - Beza's Hangover

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.

codeforcescompetitive-programming
CF 102439K - Innovations

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.

codeforcescompetitive-programming
CF 102439J - Boedium

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.

codeforcescompetitive-programming
CF 102439F - Prime or number

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.

codeforcescompetitive-programming
CF 102439C - Cockroach Racing

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.

codeforcescompetitive-programming
CF 102437H - Сэм и хранилище

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.

codeforcescompetitive-programming
CF 102433K - Computer Cache

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.

codeforcescompetitive-programming
CF 102433L - Carry Cam Failure

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.

codeforcescompetitive-programming
CF 102433M - Maze Connect

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.

codeforcescompetitive-programming
CF 102433J - Interstellar Travel

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

codeforcescompetitive-programming
CF 102433I - Error Correction

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.

codeforcescompetitive-programming
CF 102433H - Pivoting Points

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.

codeforcescompetitive-programming
CF 102433G - Glow, Little Pixel, Glow

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.

codeforcescompetitive-programming
CF 102433A - Radio Prize

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.

codeforcescompetitive-programming
CF 102428K - Know your Aliens

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.

codeforcescompetitive-programming
CF 102428J - Jumping Grasshoper

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.

codeforcescompetitive-programming
CF 102428M - Mountain Ranges

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.

codeforcescompetitive-programming
CF 102428L - Leverage MDT

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.

codeforcescompetitive-programming
CF 102428I - Improve SPAM

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.

codeforcescompetitive-programming
CF 102428H - Hold or Continue?

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.

codeforcescompetitive-programming
CF 102428G - Gluing Pictures

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.

codeforcescompetitive-programming
CF 102428F - Fabricating Sculptures

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.

codeforcescompetitive-programming
CF 102428B - Build the Perfect House

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.

codeforcescompetitive-programming
CF 102423K - Windmill Pivot

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.

codeforcescompetitive-programming
CF 102423H - Levenshtein Distance

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.

codeforcescompetitive-programming
CF 102420I - Sum of Maximums

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.

codeforcescompetitive-programming
CF 102420H - Wedding

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.

codeforcescompetitive-programming
CF 102420K - Magical XML

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.

codeforcescompetitive-programming
CF 102420B - Сильная группа

У нас есть дерево из n комнат. В каждой комнате находится один эльф с силой w[i].

codeforcescompetitive-programming
CF 102409H - Maximizing Coins

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.

codeforcescompetitive-programming
CF 102423I - Maze Connect

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.

codeforcescompetitive-programming
CF 102423A - Carryless Square Root

The operation in this problem looks like ordinary multiplication, except that every addition performed inside the multiplication discards carries.

codeforcescompetitive-programming
CF 102420C - Ловушка со свечками

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.

codeforcescompetitive-programming
CF 102411C - Cross-Stitch

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.

codeforcescompetitive-programming
CF 102409D - Lottery Ticket

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.

codeforcescompetitive-programming
CF 102407A - Сумасшедшие транспортные налоги

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.

codeforcescompetitive-programming
CF 102391C - Cleaning

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.

codeforcescompetitive-programming
CF 102423J - One of Each

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.

codeforcescompetitive-programming
CF 102423G - Jumping Path

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.

codeforcescompetitive-programming
CF 102423F - Interstellar Travel

We have (N) stars around Earth. For each star (i), three values describe its contribution to the spaceship's travel distance.

codeforcescompetitive-programming
CF 102423E - Fixed Point Permutations

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.

codeforcescompetitive-programming
CF 102423C - Elven Efficiency

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.

codeforcescompetitive-programming
CF 102420J - Малефисумма

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.

codeforcescompetitive-programming
CF 102420G - Tennis score

Searching the web

codeforcescompetitive-programming
CF 102420F - Arithmetic and blocks

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.

codeforcescompetitive-programming
CF 102420E - Ленивые лесорубы

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.

codeforcescompetitive-programming
CF 102420D - Spell

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.

codeforcescompetitive-programming
CF 102412D - The Jump from Height of Self-importance to Height of IQ Level

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.

codeforcescompetitive-programming
CF 102412E - Minimums on the Edges

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

codeforcescompetitive-programming
CF 102411M - Managing Difficulties

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.

codeforcescompetitive-programming
CF 102411J - Just the Last Digit

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.

codeforcescompetitive-programming
CF 102411H - High Load Database

We have an array of transactions (a1,a2,ldots,an), where transaction (i) contains (ai) queries. We must partition this array into consecutive groups.

codeforcescompetitive-programming
CF 102411F - Foreach

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.

codeforcescompetitive-programming
CF 102411E - Equidistant

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.

codeforcescompetitive-programming
CF 102409K - Lending Woes

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.

codeforcescompetitive-programming
CF 102409J - Best division

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.

codeforcescompetitive-programming