brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 102341G - Gurdurr

Each layer can have only one of four stable configurations that matter to the game. A completely intact layer is III. A layer with two blocks is either II. or .II, and these two cases have identical game behavior, so we can treat them as one state.

codeforcescompetitive-programming
CF 102331C - Counting Cactus

We have a simple undirected graph on at most 13 vertices. We choose a subset of its edges, while keeping the whole vertex set, and ask whether the resulting spanning graph is a cactus. A cactus is connected, and no edge may belong to two different simple cycles.

codeforcescompetitive-programming
CF 102331F - Fast Spanning Tree

We have a weighted set of vertices and a list of indexed edges. Initially there are no graph edges, so every vertex is its own connected component.

codeforcescompetitive-programming
CF 102331G - Grammarly

The graph has one vertex for every distinct non-empty substring of the input string s. From a substring t of length L, an edge goes to every distinct substring of t of length L-1.

codeforcescompetitive-programming
CF 102323F - Faster Microwaving

We are given a recommended microwave cooking time in MM:SS form and a percentage p. Chris is allowed to choose any integer number of seconds whose distance from the recommended time is at most p percent of that recommended time.

codeforcescompetitive-programming
CF 102319F - Forever Young

The students have distinct ages, so an arrangement of the class is simply a permutation of the numbers (1,ldots,s). Henry's maximum number of circled students is the length of the longest increasing subsequence of that permutation.

codeforcescompetitive-programming
CF 102319A - Andrew and Efficient Change

We have a coin system containing n distinct denominations, including denomination 1. Andrew must pay separately for every amount in the consecutive interval [l, r]. For each amount, he wants the minimum possible number of coins whose values sum exactly to that amount.

codeforcescompetitive-programming
CF 102319B - Paul's Badminton

The roads form a tree, so between any two places there is exactly one route. An employee assigned to go from a to b uses every edge on that unique path on every day from s through t. Paul pays once for an edge on a given day, regardless of how many employees use that edge.

codeforcescompetitive-programming
CF 102318F - Multimodal Transport

We have a transportation network with up to 400 cities. Every city has an associated switching cost. A package can travel between cities using one of four transport modes: AIR, SEA, RAIL, or TRUCK. Each route segment is undirected and belongs to exactly one transport mode.

codeforcescompetitive-programming
CF 102318C - Singin' in the Rain

The CD contains t tracks numbered from 1 through t, arranged cyclically. Anya specifies a sequence of tracks that must be played in exactly that order. The first requested track is already cued, so no button press is needed for it.

codeforcescompetitive-programming
CF 102302H - Log Concave Sequences

We need to count arrays of length (N), where every element is one of (0,1,2), such that every three consecutive elements satisfy [ a{i-1}a{i+1}le ai^2. ] The answer is required modulo (10^9+7).

codeforcescompetitive-programming
CF 102302I - Useless Pokemino

Think of every Pokemino as a point ((A,D)) in the plane, where attack is the horizontal coordinate and defense is the vertical coordinate.

codeforcescompetitive-programming
CF 102302B - Divples

We need to find every positive integer that is simultaneously a divisor of a and a multiple of b. The input gives the two integers a and b, with b <= a and both potentially as large as 10^12.

codeforcescompetitive-programming
CF 102297C - Brownies vs. Candies vs. Cookies

Each practice starts with a fixed number of brownies and a known number of students. Students arrive at the refreshment table in groups. Every student in a group takes exactly one brownie, but before that happens Dr.

codeforcescompetitive-programming
CF 102284G - SIS

We receive the switches one by one. Switch i has an integer label a[i], and if two switches with labels x and y are connected, that channel costs x XOR y.

codeforcescompetitive-programming
CF 102373B - Wooden Castle

We have a tree whose vertices are colored with two colors, represented by 0 and 1. We may either flip the color of one still-existing vertex, paying one operation, or choose a vertex and destroy the entire connected component of its current color containing that vertex, also…

codeforcescompetitive-programming
CF 102367A - Cake Distribution

We need to cut one cake into a small number of integer-weight pieces. The number of guests is not known in advance: it will be exactly (A), (B), or (C).

codeforcescompetitive-programming
CF 102367B - Favourite Number

A positive integer has an odd number of positive divisors exactly when it is a perfect square. Every non-square has divisors that can be paired as d and n/d, while a square has one unpaired divisor, namely its square root. So the task can be restated as follows.

codeforcescompetitive-programming
CF 102365A - Abnormal Words

We need to transform a lowercase word using a Caesar cipher. The input first tells us whether to encode or decode. Encoding moves every letter forward by a fixed shift s, while decoding moves every letter backward by the same amount.

codeforcescompetitive-programming
CF 102365C - Unjob Search

We have a tree with (N) cities. A terminal city is simply a leaf, a vertex whose degree is exactly one. The tree itself is hidden from us. We cannot inspect its edges directly.

codeforcescompetitive-programming
CF 102361G - Game on Chessboard

We have an (ntimes n) board containing at most one chess piece in each cell. Every piece is either white or black and has a positive removal value. A white and a black piece may be removed together if both are currently exposed from the bottom-left direction.

codeforcescompetitive-programming
CF 102361A - Angle Beats

For each query point (A), we have to choose two distinct original points (Pu) and (Pv). The three points must form a non-degenerate triangle with one angle equal to (90^circ). The output for that query is the number of such unordered pairs of original points.

codeforcescompetitive-programming
CF 102361H - Houraisan Kaguya

We have a prime modulus (p) and an array (a1,ldots,an), where every array value is nonzero modulo (p). For two nonzero residues (a,b), we need the smallest positive exponent (u) such that (a^u) belongs to the cyclic subgroup generated by (b). Call that value (f(a,b)).

codeforcescompetitive-programming
CF 102361C - Sakurada Reset

Asai Kei chooses a non-empty subsequence of a, while the director chooses a non-empty subsequence of b. A chosen sequence such as (2, 1, 2) is interpreted as a base-1000 number, so its value is 2 1000^2 + 1 1000 + 2.

codeforcescompetitive-programming
CF 102346L - Less Coin Tosses

We have all binary strings of length (N), representing the possible results of (N) tosses of the same possibly biased coin. Carla and Daniel must assign every chosen string to at most one of them, while some strings may remain unused.

codeforcescompetitive-programming
CF 102346K - Keep Calm and Sell Balloons

The street is a graph with two rows and (N) columns. Each house is a vertex. Two houses are connected when their positions differ by at most one row and at most one column, so horizontal, vertical, and diagonal moves are all allowed.

codeforcescompetitive-programming
CF 102346G - Getting Confidence

We have an (N times N) matrix. Row (i) represents ornament (i), and column (j) represents shelf position (j). The value (a{i,j}) measures how confident Fulano is that ornament (i) originally occupied position (j).

codeforcescompetitive-programming
CF 102346F - Forests in Danger

We need to choose an integer distance (r) around every river so that the union of all preserved regions covers at least (P%) of the rectangular territory. Each river is an axis-aligned line segment.

codeforcescompetitive-programming
CF 102346B - Buffoon

The election result is represented by an array of vote counts, where the first position belongs to Carlos and every later position belongs to a candidate who registered after him. The winner is the candidate with the largest number of votes.

codeforcescompetitive-programming
CF 102341I - Infernape

For every query, we have several Infernape placed on vertices of one fixed tree. An Infernape at vertex (vi) with power (ri) heats exactly the vertices whose tree distance from (vi) is at most (ri). A vertex is considered good if at least (k-1) of the (k) Infernape heat it.

codeforcescompetitive-programming
CF 102341E - Eevee

There are (k) stacks, each containing one fragment of every one of the (n) stones. Since every stack contains every stone exactly once, each stack is a permutation of (1,ldots,n).

codeforcescompetitive-programming
CF 102341D - Dedenne

We need to assign a distinct nonempty binary codeword to each of (n) words. The code must be prefix-free, so the codewords form the leaves of a binary trie. There is one additional restriction: a codeword may never contain 00.

codeforcescompetitive-programming
CF 102331B - Bitwise Xor

We have an array of up to (300000) integers, each using at most 60 bits, and a threshold (x). A subsequence is considered good when every pair of selected array elements has XOR at least (x).

codeforcescompetitive-programming
CF 102330C - Мячики

Petya throws one ball every minute toward Vova. The distance between them is L, and every ball moves at speed X, so a ball needs L / X minutes to reach Vova. Vova does not shoot balls immediately. He starts shooting when a ball gets within distance D of him.

codeforcescompetitive-programming
CF 102330A - Доктор Айболит

We have an array a of n animals. The value a[i] is the amount of time Doctor Aibolit needs to examine animal i. The doctor handles one animal at a time, so the animals form a single queue. For a chosen order, the first animal waits 0 time units.

codeforcescompetitive-programming
CF 102323C - Jumping Frog

We have a circular arena with (N) positions numbered from (0) to (N-1). Every position is either a rock, written as R, or a pond, written as P. The frog may start at any rock. After choosing a jump length (K), every jump moves the frog from position (i) to [ (i+K)bmod N.

codeforcescompetitive-programming
CF 102323G - Dirty Plates

We have three stacks. The dirty stack initially contains a permutation of 1..n. A type 1 operation removes between 1 and a plates from the top of the dirty stack and places them, without changing their internal order, on the intermediate stack.

codeforcescompetitive-programming
CF 102323B - Soccer Standings

We are given several independent soccer groups. Each group contains a set of uniquely named teams and a collection of already played matches. For every match, we know both teams and their final scores. From those results, we must build the complete standings table.

codeforcescompetitive-programming
CF 102319E - Enegue's Enigmatic Lanterns

We have a row of n lanterns, exactly k of them are on, and 4 <= k <= n <= 100. We can ask the judge about any subset of lanterns. If that subset contains x lit lanterns, the judge does not reveal x. Instead, it returns the number of divisors of x that are composite.

codeforcescompetitive-programming
CF 102319C - Cyclic Song

A valid Type (N) song is exactly a binary de Bruijn cycle of order (N). Its period has length (2^N), and every binary string of length (N) appears exactly once during one period. The input gives (N), followed by two length-(N) strings (S) and (T).

codeforcescompetitive-programming
CF 102318K - K-Item Shopping Spree

We have a collection of n item types. Item i has a price given to exactly two decimal places, and when constructing a shopping spree we choose exactly k items in sequence.

codeforcescompetitive-programming
CF 102318J - Multiples

For each query, we have two integers a and b. We look at every integer from 1 through b and count it if it is divisible by at least one integer from 2 through a. The answer is the size of that union of sets of multiples.

codeforcescompetitive-programming
CF 102318G - Videogame Probability

The game contains several item types. For each type, we know how many copies are required and the probability of obtaining that type on an attempt. We also know the total number of attempts available.

codeforcescompetitive-programming
CF 102318B - Simplified Keyboard

The problem uses a small custom keyboard containing all 26 lowercase letters. The letters are arranged in three rows: Two words are given for each test case. We must classify the pair into one of three categories.

codeforcescompetitive-programming
CF 102309A - APA of Orz Pandas

We are given ordinary C++ arithmetic expressions whose operands are identifiers made only from English letters. The operators are binary +, -, , /, and %, and parentheses may change the evaluation order.

codeforcescompetitive-programming
CF 102309D - Director of Orz Pandas

We have two groups of features. The first group contains (n) features and the second contains (m) features. Every feature has a positive weight, and some pairs are declared incompatible.

codeforcescompetitive-programming
CF 102309I - IPv6 Address of Orz Pandas

Each test case gives one non-negative integer representing a complete 128-bit IPv6 address. An IPv6 address has exactly eight 16-bit sections, so the first job is to write the integer as exactly 32 hexadecimal digits and split those digits into eight groups of four.

codeforcescompetitive-programming
CF 102309H - Horton and Orz Pandas

We have an undirected graph whose vertices are the Orz Pandas and whose edges are possible data links. Every edge has two positive values, a and b. For a chosen set of edges S, the communication requirement says that the chosen edges must form a connected spanning subgraph.

codeforcescompetitive-programming
CF 102309E - Expectation of Orz Pandas

There are (n) boxes arranged from left to right. A type 1 operation chooses an interval ([l,r]), a digit (x), and an offset (c). For every position (p) in that interval, where (p=l+k-1), exactly one new paper strip is placed into box (p).

codeforcescompetitive-programming
CF 102309B - Brute Force of Orz Pandas

The program generates the standard recursive solution to the Tower of Hanoi problem. For a tower of n disks, it first moves the top n-1 disks from the source peg to the auxiliary peg, then moves disk n from the source to the destination, and finally moves the n-1 disks from…

codeforcescompetitive-programming
CF 102307E - Extreme Image

We have (n) luminous bodies, each described by its distance from Earth and its angular position around Earth. The observatory can choose any radial interval of length (d), written as ([x,x+d]), and any angular interval of length (alpha), written as ([omega,omega+alpha]).

codeforcescompetitive-programming
CF 102307C - Common Subsequence

We have two DNA strings A and B, both of length n. The only characters that can appear are A, T, G, and C. We do not need to construct the common subsequence. We only need to decide whether its maximum possible length is at least 0.99n.

codeforcescompetitive-programming
CF 102307F - Fraction Formula

Each input line is an arithmetic expression built from fractions, addition, subtraction, and parentheses. A fraction appearing in the expression has a numerator from 0 through 100 and a positive denominator from 1 through 20.

codeforcescompetitive-programming
CF 102307A - Amazon

We are given several pairs of points. Each pair determines an infinite straight subway line through those two points. The actual segment between the points is irrelevant because the subway line extends indefinitely.

codeforcescompetitive-programming
CF 102302K - Candies

We have an integer array C of length N. A candy sequence is any non-empty contiguous part of this array, and its value is the sum of its elements. The required answer is not the number of positions where a valid sequence occurs.

codeforcescompetitive-programming
CF 102302J - Weird Sanchola

We need to choose one prime number and change every element of the array into that prime. Changing an element by one costs exactly one operation, so if the chosen prime is p, the total cost is f(p)= i=1 ∑ N ​ ∣a i ​ −p∣.

codeforcescompetitive-programming
CF 102302C - Rectangles

We have at most 2000 distinct points on a coordinate plane. A valid rectangle must use four of these points as its corners, its sides must be horizontal or vertical, and there must be no other given point anywhere inside the rectangle or on one of its four sides.

codeforcescompetitive-programming
CF 102299C - Crystal Matryoshkas

We maintain a collection of matryoshkas. Every doll has a positive integer weight and a unique identifier. A doll can contain several smaller dolls, but the total weight of everything directly or indirectly inside an outer doll must not exceed the outer doll's weight.

codeforcescompetitive-programming
CF 102299B - Russo's Russian

We need to decide whether one input line can be generated from the nonterminal M of the given grammar. The line contains digits, whitespace, and the punctuation characters :, The grammar describes three layers. T is either a digit sequence or a complete { M } expression.

codeforcescompetitive-programming
CF 102297G - Towers of Hanoi Grid

We have an (n times n) directed grid. A disk can move only one cell down or one cell right, so every disk follows a monotone path from the upper-left corner to the lower-right corner.

codeforcescompetitive-programming
CF 102297H - Reach for the Stars

The stamp is a fixed axis-aligned cross consisting of five cells: the center cell and its four orthogonally adjacent cells. A stamping turns those five paper cells black.

codeforcescompetitive-programming
CF 102297B - Medal Ranking

Each test case describes the medal counts of two countries, USA and Russia. The six integers are ordered as USA gold, silver, bronze, followed by Russia gold, silver, bronze. There are two independent ways to decide whether USA wins.

codeforcescompetitive-programming
CF 102284H - Музыкальный фреш

We have an array of $N$ songs. Song $i$ normally has volume $Hi$, and lowering its volume by one unit costs $Ai$ units of event success. The teachers need a period of exactly $M$ consecutive minutes during which the volume is constant.

codeforcescompetitive-programming
CF 102284C - Баскетбольная зарядка

We have two rows of (n) students. Student (i) in the first row has height (ai), and student (i) in the second row has height (bi). A team is formed by taking students from left to right, so the indices of chosen students must be strictly increasing.

codeforcescompetitive-programming
CF 102284B - Большие часы и маленькая окружность

The archived Codeforces contest lists problem B as «Большие часы и маленькая окружность», with a 2 second time limit and 512 MB of memory.

codeforcescompetitive-programming
CF 102282A - Первая задача

We need to choose a positive integer (x) such that (x^n) is divisible by (m), and among all such positive integers we need the smallest one. If no such (x) exists, we print ABSENT.

codeforcescompetitive-programming
CF 102282B - Ещё одна

We need to count the positive integers from 1 through r that are coprime with n. Two numbers are coprime when their greatest common divisor is exactly 1. The input contains two integers, n and r, each at most 10^9.

codeforcescompetitive-programming
CF 102281B - Кулинарная задача

We have a triangular cookie cutter whose side lengths are (a), (b), and (c), and a circular cookie cutter with radius (r).

codeforcescompetitive-programming
CF 102281C - Магическая задача

We are given the side length n of a square. The square must contain every integer from 1 through n² exactly once, with every row, every column, and both main diagonals having the same sum. The required output is only that common sum, not the square itself.

codeforcescompetitive-programming
CF 102280C - Экзамен по вождению

There are (n) drivers and (n) Gazelle cars. Each driver receives exactly one car, and every car is assigned to exactly one driver, so an assignment is a permutation of the cars. A driver is called fixed if they receive their own car.

codeforcescompetitive-programming
CF 102280B - Сумасшедшие гонки на маршрутках

We have two independent minibuses. During the one-hour interval from 08:00 to 09:00, each minibus reaches the intersection exactly once, and its arrival time is uniformly distributed over the 3600 seconds of the hour. The traffic light starts with green at time 0.

codeforcescompetitive-programming
CF 102280G - Специальный заказ

We have a starting point on a road and a destination somewhere away from that road. The straight-line distance between the starting point and the destination is s, while the perpendicular distance from the destination to the road is h.

codeforcescompetitive-programming
CF 102280F - Неожиданная зима

Each line in the notebook contains only a driver's surname. A driver writes the surname once when leaving the garage and once when returning. The notebook does not tell us which occurrence is a departure and which is a return.

codeforcescompetitive-programming
CF 102280H - Задача Шумахера

We are given two prime numbers, (p) and (q), and need to decide whether [ (p+1)^q ] is a perfect square. The numbers can contain up to (1000) decimal digits, so they are far beyond ordinary machine integer types.

codeforcescompetitive-programming
CF 102280E - Штраф

We have a collection of individual banknotes. Each banknote has a denomination, and every banknote can be used at most once. Given a fine amount p, we need to choose some of the available banknotes whose total value is as small as possible while still being at least p.

codeforcescompetitive-programming
CF 102280D - Тарификация

A route has a value k. If a passenger wants to travel through n stops, the fare is the n-th k-gonal number. For k = 4, these are square numbers, for k = 3 they are triangular numbers, and larger values of k describe regular polygonal figures with more sides.

codeforcescompetitive-programming
CF 102280A - Камень, ножницы, бумага

We have n drivers, initially ordered by the positions they occupy in the log. The log is a single string of R, S, and P, but the boundaries between game rounds have been erased.

codeforcescompetitive-programming
CF 102281K - Системная задача

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

codeforcescompetitive-programming
CF 102281L - Необычная задача

The function foo(a, b) repeatedly subtracts a from b until the current value becomes non-positive. The final value is zero exactly when a divides b. The function then recursively replaces a by 2a and 2a+1, so starting from a=1 it can eventually reach every positive integer.

codeforcescompetitive-programming
CF 102281M - Антинаучная задача

The wormholes form a directed graph. Each known transition goes from one wormhole to another and has one of two costs. A hypertransition costs one ant-hour, while a null transition costs zero. The ship starts at wormhole 1 and has to reach wormhole n.

codeforcescompetitive-programming
CF 102281J - Кольцевая задача

We have (n) separate chains. The (i)-th chain contains (ai) rings. An operation opens one ring, removes it from its original chain, and then closes that ring around the ends of two chains. The opened ring therefore becomes a connector between two pieces.

codeforcescompetitive-programming
CF 102281I - Детская задача

We are given an addition written with words instead of digits, such as VOLVO+FIAT=MOTOR. Every distinct letter must be assigned a digit from 0 through 9. Two different letters must receive different digits, while every occurrence of the same letter receives the same digit.

codeforcescompetitive-programming
CF 102281H - Спичечная задача

We have two matchboxes, each initially containing exactly n matches. Every time Professor X needs a match, he chooses one of the two pockets uniformly at random and tries to take a match from that box.

codeforcescompetitive-programming
CF 102281G - Территориальная задача

We have an n × m rectangular grid of unit cells. Among these cells, k are marked as important. We need to count every axis-aligned rectangle of cells that contains all marked cells. There is one restriction: the chosen rectangle must not be the entire grid.

codeforcescompetitive-programming
CF 102281F - Сложная задача

We have a collection of identical generators. The documentation says that exactly n generators produce k joules during m minutes. The required system must produce at least q joules during p minutes.

codeforcescompetitive-programming
CF 102281E - Инновационная задача

We start with n repair robots and m independent nanodamages. During one second, every existing robot chooses exactly one action. It either repairs one damage, or spends the second creating one new robot. A newly created robot becomes available from the following second.

codeforcescompetitive-programming
CF 102281D - Боевая задача

We have three points in three-dimensional space. The first point is the position of our spacecraft and laser cannon, the second is the center of an enemy spherical spacecraft together with its radius, and the third is the point selected by the targeting system.

codeforcescompetitive-programming
CF 102281A - Простая задача

We have a single pile of n cookies. Two players remove cookies alternately, with Professor X moving first. A legal move removes p^k cookies, where p is prime and k is a nonnegative integer. Since k = 0 is allowed, removing exactly 1 cookie is always legal.

codeforcescompetitive-programming
CF 102282J - Последняя задача

We have two strings, s1 and s2. The first string is the text that should have been copied, while the second is the text that was actually written. During copying, two kinds of mistakes are allowed: a character can be omitted, or a character can be replaced by another character.

codeforcescompetitive-programming
CF 102282I - Произведения

We have an (n times n) grid. Some cells contain positive integers and the rest contain zero. Every row and every column must contain exactly two nonzero cells.

codeforcescompetitive-programming
CF 102282H - Без имени

We have two circles in the Cartesian plane. Each circle is described by the integer coordinates of its center and its positive integer radius. The task is to determine how many points belong to both circles and to print those points with sufficient numerical precision.

codeforcescompetitive-programming
CF 102282G - Баян

The building is organized into entrances, floors, and apartments. Every entrance contains exactly n floors, and every floor contains exactly m apartments.

codeforcescompetitive-programming
CF 102282F - Мастер угадывания цифр

The task looks like an ordinary arithmetic problem, but the central difficulty is deliberately hidden in the statement. For test number (k), the author generated the answer as the last decimal digit of [ g(k)=nk+c, ] where (n) and (c) are fixed integers chosen by the author.

codeforcescompetitive-programming
CF 102282E - О дружбе

The input describes an undirected graph whose vertices are people and whose edges represent pairs of people who are "true friends". The company is guaranteed to be connected, meaning that for every pair of people there is a chain of true-friend relationships between them.

codeforcescompetitive-programming
CF 102282D - Робот в лабиринте

We have a rectangular grid of at most (100 times 100) cells. Some cells are walls and cannot be entered, while the remaining cells are traversable. One traversable cell contains the robot initially.

codeforcescompetitive-programming
CF 102282C - Неутешительная задача

A snail starts at height 0 and climbs Mount Fuji, whose height is fixed at 3776 meters. During each day it climbs exactly n meters. If it has not reached the summit after that climb, the following night makes it slide down m meters.

codeforcescompetitive-programming
CF 102284M - Трискайдекафобия

We need to work with the increasing sequence of all positive integers whose prime factors belong to the fixed set {2, 3, 5, 7, 11}. Such numbers can be written exactly as [ 2^a3^b5^c7^d11^e, ] where all five exponents are nonnegative integers.

codeforcescompetitive-programming
CF 102284L - Выбор вечёрки

There are (n) students, and each student names one of (k) possible drinks. Andrew has exactly (lceil n/2rceil) packages. Each package contains two half-portions, so one package can satisfy at most two students, and both of those students must have requested the same drink.

codeforcescompetitive-programming
CF 102284K - Пришёл Демид и всё проверил

We have a queue of (N) packages. Each package belongs to one of four groups, represented by the digits 6, 7, 8, and 9. Reading the groups from left to right gives the number whose value defines the beauty of the queue.

codeforcescompetitive-programming
CF 102284J - Гриша после дискотеки

We have Grisha's string s, and a collection of letter cards represented by another string t. Every character of t corresponds to one physical card, so only the number of available copies of each letter matters.

codeforcescompetitive-programming