brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105449A - Скип или не скип

We are given a process that starts from task 1 and moves through a system that dynamically chooses the next task based on what we previously did. Each task has a score value and also a “jump limit” that affects where the next available task can come from if we skip.

codeforcescompetitive-programming
CF 105449E - Покупка колы

We are given a vending machine with several hidden compartments, each containing some number of cans. There are also the same number of buttons, but the labels are lost, so each button is secretly wired to exactly one compartment via a fixed unknown permutation.

codeforcescompetitive-programming
CF 105449B - Отгадай строку

We are given a hidden string of length $n$, built from the first $k$ lowercase Latin letters. We are not given the string directly. Instead, we are given two pieces of information that uniquely determine it.

codeforcescompetitive-programming
CF 105449C - Холмы и ямы

We are given an array of integers that represents terrain heights along a one-dimensional road. Each position has either surplus sand (positive value) or a deficit that must be filled (negative value).

codeforcescompetitive-programming
CF 105450J - Candy Production

We are given a collection of machines, and each machine can be configured in one of three productive roles or left unused.

codeforcescompetitive-programming
CF 105450A - Minimize Sour Difference

We are given a list of integer sourness values representing candies. Alice is allowed to remove exactly $k$ candies from this list, leaving $n-k$ candies behind.

codeforcescompetitive-programming
CF 105450F - Houdini

We are given a tree with one value on each node, representing how many candies sit in that container. The magician is allowed to delete edges, which breaks the tree into connected components.

codeforcescompetitive-programming
CF 105450B - Sour Strip Shapes

We are given two axis-aligned squares on a 2D grid. Each square is described by the coordinates of its lower-left corner and a side length.

codeforcescompetitive-programming
CF 105453F - Anomia

We are given a rectangular grid that behaves like a small city map. Some cells are roads, some are buildings that block movement, and some contain police officers who look in a fixed direction with limited vision.

codeforcescompetitive-programming
CF 105453B - Bureaucracy

We are given a queue of people standing in a fixed initial order from 1 to N. Each person has a workload Ri, representing how much processing time they need at a government office. The office works in rounds.

codeforcescompetitive-programming
CF 105454K - Квантовые каналы связи

We are given a binary string consisting only of opening and closing parentheses. From this string, we consider subsequences, meaning we may delete characters without changing the order of the remaining ones.

codeforcescompetitive-programming
CF 105454H - Как же это посчитать?

We are given an interval of integers from a to b, and we need to count how many numbers inside this interval have exactly six positive divisors.

codeforcescompetitive-programming
CF 105454G - Сестра и братья

We are dealing with a situation where two baskets of apples exist. One basket contains a known amount $X$, the second contains an unknown positive number $Y$, strictly smaller than $X$.

codeforcescompetitive-programming
CF 105454A - Очень длинное условие

We are given a rooted tree with vertices numbered from 1 to n, where each vertex except the root has a parent given explicitly. The task is to assign one of k colors to every vertex such that no edge connects two vertices of the same color.

codeforcescompetitive-programming
CF 105454C - Почтальон Печкин в большом городе

The city is an undirected connected graph where each house is a vertex and each road is an unweighted edge. A postal hub must be placed at exactly one vertex.

codeforcescompetitive-programming
CF 105455B - Bureaucratic Games

We are given a linear sequence of service windows, and at each window there is exactly one possible transformation between documents: if you currently hold a specific document, you may choose to perform a procedure that converts it into another document.

codeforcescompetitive-programming
CF 105455A - Juan's Femur

We are given multiple independent scenarios. Each scenario provides three positive integers representing the lengths of three bone fragments left after a fracture.

codeforcescompetitive-programming
CF 105456C - Jan's Cookies

We are given several independent scenarios. In each one, there are many cookies, each cookie belongs to a type and has a deadline time when it disappears.

codeforcescompetitive-programming
CF 105456B - Deleting Letters from the SMS

We are given a string of lowercase letters representing an SMS message. Pedro is required to shorten it by deleting exactly $n - k$ characters while keeping the relative order of the remaining characters unchanged.

codeforcescompetitive-programming
CF 105457A - Words

We are given multiple independent test cases. Each test case consists of two strings of equal length, and some positions in both strings may contain unknown characters represented by a question mark.

codeforcescompetitive-programming
CF 105458C - Flipping Rectangles

We are given a grid of size $n times m$ filled with two types of cells, black and white. The goal is to turn every cell into white using a specific operation.

codeforcescompetitive-programming
CF 105459M - Weird Ceiling

We are given a single integer $n$, and we conceptually evaluate a function $f(n, i)$ for every integer $i$ from 1 up to $n$. Each value of $f(n, i)$ is defined by a procedure that scans integers downward from $i$ to 2 and checks divisibility against $n$.

codeforcescompetitive-programming
CF 105459I - A Brand New Geometric Problem

We start with a collection of positive integers that represent edge lengths of an $n$-dimensional hyper-rectangle. Two aggregate values matter: the sum of all edge lengths and the product of all edge lengths.

codeforcescompetitive-programming
CF 105459E - Marble Race

There are $m$ marbles, each moving on the real line. Each marble first picks one of $n$ fixed starting positions on the negative side of the axis uniformly at random, independently of all others.

codeforcescompetitive-programming
CF 105459A - Build a Computer

We are asked to construct a compact representation of all binary numbers in a given inclusive interval $[L, R]$. Instead of listing these numbers directly, we must build a directed acyclic graph with a single source and a single sink, where every valid path from source to sink…

codeforcescompetitive-programming
CF 105461L - Drawing Rectangles

We are repeatedly choosing axis-aligned rectangles inside an $n times m$ grid whose corners lie on integer coordinates.

codeforcescompetitive-programming
CF 105461I - Periodic Recurrence

We are given a sequence generated by a linear recurrence modulo a fixed integer $M$. The sequence starts from two initial values $a0$ and $a1$, and every next element is formed by combining the previous two using fixed coefficients $A$ and $B$, then reducing the result modulo…

codeforcescompetitive-programming
CF 105461F - Autobahn Optimization

We are given a sequence of cars that arrive in a fixed order. Each car has a maximum possible speed, and we are allowed to assign each car to one of two lanes. The order of cars inside each lane is the same as the original order, so each lane forms a subsequence.

codeforcescompetitive-programming
CF 105461A - Matrix Minors

We are given a square matrix and asked to compute a very specific derived matrix. For every cell $(i, j)$, we conceptually remove row $i$ and column $j$ from the original matrix and compute the determinant of the remaining $(n-1) times (n-1)$ matrix.

codeforcescompetitive-programming
CF 105461C - Concert Lineup

We are maintaining a dynamic ordering of $n$ distinct items representing artists in a concert lineup. The lineup is stored as a sequence, and we repeatedly apply operations that depend on positions inside the current sequence. Each operation gives an even number $k$.

codeforcescompetitive-programming
CF 105465L - LIS on Grid

We are given a grid with $n$ rows and $m$ columns. For each column $j$, we must choose exactly $aj$ cells to paint black. All other cells remain white. The choices inside each column are free, as long as the number of black cells per column is fixed.

codeforcescompetitive-programming
CF 105465H - High Towers

We are given a line of positions representing towers, and for each position we are told how many other towers that tower must be able to “see” or communicate with. Two towers can communicate if, between them, there is no tower strictly higher than both endpoints.

codeforcescompetitive-programming
CF 105465E - Eliminate Tree

We are given a tree where every operation changes the structure in a very specific way. One type of operation inserts a new vertex and connects it to exactly one existing vertex, effectively creating a new leaf.

codeforcescompetitive-programming
CF 105465A - AND-OR closure

We are given a set of distinct integers, and we are allowed to repeatedly apply two operations: bitwise AND and bitwise OR between any two elements. Every time we apply one of these operations, the result must also belong to the set.

codeforcescompetitive-programming
CF 105471B - Counting Multisets

We are counting how many multisets of non-negative integers satisfy three simultaneous constraints, but the constraints are expressed in a slightly indirect way. Each multiset has size $n$, so it contains exactly $n$ elements when multiplicities are expanded.

codeforcescompetitive-programming
CF 105472K - Keep it Cool

We are given a fridge divided into several independent slots. Each slot already contains some number of cold soda bottles, and each slot also has a fixed maximum capacity.

codeforcescompetitive-programming
CF 105472I - Incremental Induction

We are given the complete results of a round-robin tournament among $n$ contestants, but the results are encoded incrementally. For every pair of contestants $i < j$, we know whether contestant $j$ defeated contestant $i$.

codeforcescompetitive-programming
CF 105472F - Flow Finder

The tree describes a system where every node carries a nonnegative “flow value”. Leaves represent independent sources of water and may take any positive integer value. Every internal node represents a confluence, and its value is exactly the sum of the values of its children.

codeforcescompetitive-programming
CF 105472E - Eeny Meeny

We are simulating a selection process on a circular arrangement of children. The children stand in a fixed clockwise order, and we repeatedly remove one child at a time based on a counting rule defined by a given rhyme, which is just a sequence of words.

codeforcescompetitive-programming
CF 105472B - Building Boundaries

We are given three rectangular buildings, each with fixed side lengths, and we are allowed to rotate each rectangle by 90 degrees. The goal is to place all three rectangles on a single larger axis-aligned rectangle such that they do not overlap.

codeforcescompetitive-programming
CF 105472C - Cocoa Coalition

We are given a rectangular chocolate bar made of unit squares arranged in an n by m grid. We repeatedly take a single rectangular piece and split it into two smaller rectangles by making one straight cut, either horizontally or vertically.

codeforcescompetitive-programming
CF 105475A - Pizzas

Each attendee requests a number of pizza slices, and every requested slice has a specified topping. A pizza shop sells pizzas in only one topping per pizza, and each pizza is always cut into exactly 8 equal slices.

codeforcescompetitive-programming
CF 105475C - Word Expansion

We start with a single string made of lowercase letters. Each letter is not static: it expands into another string according to a fixed substitution table of size 26. If a character is x, it is replaced by the string px.

codeforcescompetitive-programming
CF 105476E - Ninjas

We are given a tree representing a palace, where each room is a node and corridors are edges. Some rooms are special: exactly the leaves of the tree, those with only one corridor, contain doors. Two groups enter the tree from two different leaves.

codeforcescompetitive-programming
CF 105476B - Multiples of 11

We are given a string of digits for each test case and asked to count how many of its contiguous substrings represent integers divisible by 11. Each substring is interpreted as a decimal number, but substrings may start with zero, so leading zeros do not affect divisibility.

codeforcescompetitive-programming
CF 105476A - Distractions

We are working with a sequence of strings where each term is constructed from the previous one by describing it in terms of consecutive runs of digits.

codeforcescompetitive-programming
CF 105477C - Decoding Permutations

We are given a sequence of constraints that come from a hidden permutation of the numbers from 1 to n. Instead of the permutation itself, we receive, for each position i, a value ci that counts how many earlier positions contain values smaller than the value placed at position i.

codeforcescompetitive-programming
CF 105477B - Russian Roller Coasters

We are asked to count how many valid “roller coasters” can be formed from a fixed number of segments, where each segment moves one unit horizontally and either goes up or down by one unit vertically.

codeforcescompetitive-programming
CF 105478C - Greed

Each test case gives a shop structured as several independent stacks of items. In each stack, items are arranged in a fixed order from top to bottom, and you are only allowed to access the next item in a stack if you have already bought everything above it.

codeforcescompetitive-programming
CF 105481K - 可重集合

We start with an empty multiset $S$. Each operation either inserts one occurrence of a number $x$ into $S$, or removes one occurrence of $x$ that is guaranteed to exist.

codeforcescompetitive-programming
CF 105481I - 野兽节拍

We are given a long string made of lowercase letters. We are allowed to choose a pattern string T of length three.

codeforcescompetitive-programming
CF 105481F - 飞沙走蛇

We are given a directed graph on up to 500 vertices. Every vertex has the same number of outgoing and incoming edges, and the graph is strongly connected.

codeforcescompetitive-programming
CF 105481E - 俄式简餐

We are given a rectangular grid with $n$ rows and $m$ columns, and two kinds of tetromino pieces. Each piece occupies exactly four unit cells, and we are allowed to rotate or reflect each piece arbitrarily before placing it on the grid.

codeforcescompetitive-programming
CF 105481C - 插排串联

The system is a rooted tree that models an electrical setup. The root is a single socket with a fixed power limit, and every other node is either an electrical device or a power strip.

codeforcescompetitive-programming
CF 105481B - 比分幻术

We are given a scoreboard written in the form A-B, where A represents Alex’s score and B represents the opponent’s score. Both values are single digits from 0 to 9. The system applies a “score illusion” operation that simply swaps the two values.

codeforcescompetitive-programming
CF 105485N - 低谷(hard)

We are given a sequence of numbers and allowed to perform a fixed number of operations. Each operation chooses a single position and decreases that value by exactly one. After doing this up to k times in total, we want to maximize how many indices become “valleys”.

codeforcescompetitive-programming
CF 105485L - 数组交换

We are given a single array of odd length. The process runs for exactly half of its length rounded down, and each round always removes the first two elements after allowing a single adjacent swap somewhere in the array.

codeforcescompetitive-programming
CF 105485I - 智力博弈

We are given an array that contains each integer from 1 to n exactly twice, but the order is arbitrary. Think of it as a sequence of 2n labeled cards where every label appears exactly two times. Two players then play a game on this sequence.

codeforcescompetitive-programming
CF 105485E - 伤害最大化

We are scheduling actions over a short time horizon of at most 18 steps. At each time step, we must choose exactly one of four skills.

codeforcescompetitive-programming
CF 105485F - 猫猫虫困境 II

We are working on a one-dimensional number line from 1 to n. On this line there are two types of special points: p starting positions for independent agents (called catworms in the statement), and k teleport portals. There is also a single target position g.

codeforcescompetitive-programming
CF 105485B - 借阅图书

We are simulating a library system where books are stored in a stack and readers interact with the system over a sequence of time-stamped events. The books are initially arranged so that book number 1 is at the bottom and book number n is at the top.

codeforcescompetitive-programming
CF 105486M - Two Convex Holes

We are tracking how a point light source moves in a horizontal plane while two fixed convex “gates” in space restrict which points on the ground can be illuminated.

codeforcescompetitive-programming
CF 105486F - Double 11

We are given a list of positive values $si$, each representing the daily demand of a product type. We must partition these $n$ items into exactly $m$ non-empty groups. For each group $j$, we assign a positive real parameter $kj$. Two quantities are defined from this construction.

codeforcescompetitive-programming
CF 105486B - Athlete Welcome Ceremony

We are given a line of n volunteers, each position already partially assigned one of three costume types or left unassigned. The fixed assignments are immutable, while the unassigned positions must be filled using costumes of type a, b, or c.

codeforcescompetitive-programming
CF 105487L - Puzzle

We are given four kinds of puzzle pieces, labeled A, B, C, and D, with limited quantities of each. Each piece has special edge geometry, and pieces can only be placed next to each other if their touching edges are compatible in a complementary way, meaning one side must “fit…

codeforcescompetitive-programming
CF 105487F - Perfect Square

We are given a sequence of positive integers. For each number $ai$, we must choose a divisor $di$. After making all choices, we look at the product $D = prod di$. Among all possible choices, we only care about those where this product is a perfect square.

codeforcescompetitive-programming
CF 105487C - CCPC

We are given a single long string consisting only of uppercase letters. We are allowed to rearrange its characters arbitrarily. After rearranging, we look at how many times the pattern “CCPC” appears as a contiguous substring in the resulting string.

codeforcescompetitive-programming
CF 105492L - Levelling Locks

We are given a line of water-filled chambers, each with its own initial water level. All adjacent chambers are separated by gates, and initially every gate is closed, so nothing is connected.

codeforcescompetitive-programming
CF 105492H - Horse Habitat

We are given a large rectangular grid where each cell is either usable terrain or blocked terrain. A usable cell can be part of a training course, while a blocked cell cannot.

codeforcescompetitive-programming
CF 105492B - Buggy Blinkers

We are given a directed graph where each node represents an intersection and each edge corresponds to a one-way road in one of the four cardinal directions.

codeforcescompetitive-programming
CF 105493F - Volunteering

We are given a fixed large interval on a number line, together with several smaller intervals. Each small interval contributes coverage to some portion of the large interval.

codeforcescompetitive-programming
CF 105493B - Scientific Hypotheses

We are given a sequential process of “reactions” indexed from 1 to n. At each step i, we assign a value p[i], and this value is constrained from above by a global limit pmax.

codeforcescompetitive-programming
CF 105494F - Traffic Lights

We are simulating a bus moving through a sequence of traffic lights. Between intersections, the bus spends a fixed amount of travel time, and at each intersection it may need to wait depending on the current state of a periodic traffic signal.

codeforcescompetitive-programming
CF 105494C - Linear Maze

We are given a sequence of rooms indexed from 1 onward, and we process them strictly in order. While moving through the prefix of rooms, we maintain a single integer value called the current answer. Each room contributes in one of two ways.

codeforcescompetitive-programming
CF 105498F - Make Permutation

We are given an array of integers, and for each element we are allowed to repeatedly turn off any single set bit, but only up to once per bit per element, which is equivalent to saying each number can be reduced to any value obtainable by subtracting a sum of distinct powers…

codeforcescompetitive-programming
CF 105498C - Expected Final Score

We start with a row of $n$ positions, each containing a distinct element. A pointer $p$ is also given, initially somewhere between $0$ and $n$, inclusive. We repeatedly remove elements from the current row until nothing remains.

codeforcescompetitive-programming
CF 105505K - Kool Strings

We are given a binary string and a threshold value $K$. The string is considered “bad” if it contains a run of $K$ or more identical consecutive characters, meaning a block like $0000$ when $K = 4$, or $111$ when $K = 3$.

codeforcescompetitive-programming
CF 105505F - Finding Privacy

We are given a row of $N$ identical toilets, all initially empty. People arrive one after another, and each person must choose a toilet that is currently empty and also has no occupied neighbor on either side.

codeforcescompetitive-programming
CF 105505A - Append and Panic!

We are given a single uppercase string that was produced by a two-step process. First, someone had an original string t. Then they created a second string by taking all distinct letters of t, sorting them alphabetically, and writing each letter once.

codeforcescompetitive-programming
CF 105507A - Покупка велосипеда

We are asked to pay an exact amount using only two coin types, one worth 2 units and the other worth 5 units. The goal is not just to determine whether the sum can be formed, but to construct a combination of coins whose total value is exactly the required amount and uses as…

codeforcescompetitive-programming
CF 105530F - Nice (Hard Version)

We are working with numbers formed from decimal strings, but only two digits actually matter: 6 and 9. A number is considered “nice” if it can be interpreted under a very specific ordering rule that effectively treats these two digits as comparable states, and all other…

codeforcescompetitive-programming
CF 105530A - GCD Sort

We are given a permutation of size $n$, meaning each number from $1$ to $n$ appears exactly once but in arbitrary order across positions $1$ to $n$. The task is to transform this permutation into the sorted order where value $i$ sits at position $i$.

codeforcescompetitive-programming
CF 105535L - Late Autumn Set of Cards

We are given a multiset of positive integers written on cards. From these cards, we may select any subset, and the value of that subset is defined as the product of all selected numbers.

codeforcescompetitive-programming
CF 105535J - Jolly Polygon

We are asked to construct a simple polygon with exactly n vertices placed on integer grid points within a large bounding box.

codeforcescompetitive-programming
CF 105535H - Huh? Oh, Yes, Welcome to the Contest!

The task simulates a fixed registration dialogue for a contest team, where the only variable part is the team name.

codeforcescompetitive-programming
CF 105535F - Fairly Easy Problem

We are given a sequence of fixed points $C1, C2, dots, Cn$ on a plane and a special point $D$. For each $Ci$, we must choose a circle centered at $Ci$, with radius $ri$.

codeforcescompetitive-programming
CF 105535E - Enter the Museum

We are given a connected undirected graph that forms a tree, rooted at room 1. Each room contains a number of exhibits, and the total number of exhibits across all rooms is at most 2 · 10^5. Petya starts at room 1 and must end at room 1.

codeforcescompetitive-programming
CF 105535C - Confusion

We are given a fixed 32-bit unsigned integer $a$. For each test case, we must find all 32-bit unsigned integers $b$ such that two quantities become identical when viewed modulo $2^{32}$: the first quantity is the power $a^b$, computed in the usual mathematical sense, and the…

codeforcescompetitive-programming
CF 105535B - Byte Pair Encoding

We are given a sequence of bytes, each value initially in the range from 0 to 255. The process repeatedly compresses adjacent pairs by repeatedly selecting a specific ordered pair of values and collapsing all its occurrences in one batch operation.

codeforcescompetitive-programming
CF 105536B - Рафаэль и Кейси Джонс

We are given a collection of independent encounters indexed by $i$. For each encounter there are two time costs, $ai$ and $bi$, corresponding to how much work is required if it is handled by two different fighters.

codeforcescompetitive-programming
CF 105536D - Собеседование в Сбер

We are given a sequence of tasks laid out in a line, where each task has an integer difficulty. A character named Vanya has a skill level that starts at a low value and can increase as he completes tasks.

codeforcescompetitive-programming
CF 105544B - Recurring Decimal to Fractions

The problem asks us to evaluate a real number that is given in a mixed decimal form, where part of the decimal expansion does not repeat and another part repeats forever.

codeforcescompetitive-programming
CF 105544M - Task scheduler

Each test case describes a very small scheduling system that receives a list of tasks. Every task has an identifier and a priority value, and the system must decide the order in which tasks are executed.

codeforcescompetitive-programming
CF 105544L - Nine Never

We are asked to split a given number of soldiers into several nonempty groups whose sizes are positive integers summing to $N$.

codeforcescompetitive-programming
CF 105544K - Chemical Storage

We are given a tree describing a network of storage rooms. Each room is a node, and each connection is a railroad. The structure is not arbitrary: it has a strong restriction that every node lies within distance at most two from a single central path.

codeforcescompetitive-programming
CF 105544J - Lead Time Estimation

We are given a production system that can be modeled as a directed acyclic graph of jobs. Each job takes a fixed amount of time to process, and moving from one job to another incurs an additional transfer time.

codeforcescompetitive-programming
CF 105544I - The Pentagon Conjecture

We are given several test cases. Each test case describes an undirected simple graph, but not in the usual edge-list form. Instead, the graph is specified indirectly as a collection of triangles.

codeforcescompetitive-programming
CF 105544H - Bank Deposit Challenge

We are given a fixed amount of cash and a list of bank deposit opportunities. Each opportunity requires spending a specific amount of money to participate, and in return it yields a fixed amount of interest.

codeforcescompetitive-programming
CF 105544G - A Packing Problem

We are given a set of items and a set of boxes. Each box has a fixed capacity $T$. Each item has one of two possible sizes, and these sizes are very “polarized”: every item is either very small (at most $T/4$) or very large (at least $3T/4$).

codeforcescompetitive-programming
CF 105544E - Slabstones Rearrangement

We are given a set of axis-aligned rectangular slabs placed inside a larger rectangular garden. Each slab has a fixed vertical position, meaning its bottom and top y-coordinates are immutable, but we are allowed to shift slabs horizontally left or right.

codeforcescompetitive-programming