brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105358H - Points Selection

We are given a set of points on a grid, each point having an integer position and a weight. For any rectangle anchored at the origin and defined by coordinates $(a, b)$, we look at all points whose $x$-coordinate is at most $a$ and whose $y$-coordinate is at most $b$.

codeforcescompetitive-programming
CF 105358B - Mountain Booking

We are given a tree on $n$ nodes where each edge has a weight. Over time, the tree is modified in a very controlled way: each day removes exactly one existing edge and adds exactly one new edge, and the structure always remains a tree.

codeforcescompetitive-programming
CF 105363A - Hello!

We are given several short strings, and for each one we must decide whether it can be rearranged to form the word “hola”. Rearranging means we are allowed to permute the characters freely, but we cannot add or remove any character.

codeforcescompetitive-programming
CF 105364C - Numbers in the Grid

We are working with a rectangular grid that starts completely empty in the sense that every cell initially holds zero. Then we perform a sequence of operations.

codeforcescompetitive-programming
CF 105380D - Make It Good

We are given an array and we only care about its prefixes. For each prefix, we must decide whether it has a special property called “good”.

codeforcescompetitive-programming
CF 105381K - King's Challenge

We are given multiple queries. Each query describes two integers $n$ and $k$, and asks us to work with the number formed by selecting $k$ distinct elements from a set of size $n$, ordered, which is the falling factorial $$P(n,k) = n cdot (n-1) cdot dots cdot (n-k+1).

codeforcescompetitive-programming
CF 105381F - Destroying Monsters

We are given several test cases. Each test case describes a set of monsters placed on a number line and a set of weapons. Every monster sits at a single integer coordinate, and multiple monsters can share the same position.

codeforcescompetitive-programming
CF 105381A - Trip Counting I

We are working with a complete undirected graph on $n$ countries, but some edges have been destroyed. After these removals, we are left with a simple undirected graph.

codeforcescompetitive-programming
CF 105383J - Just Round Down

We are given a single positive real number written as a string with a decimal point. The task is to compute its floor, meaning the greatest integer that does not exceed the value, and output that integer without any decimal part.

codeforcescompetitive-programming
CF 105383G - Game of Rounding

We are given an array of non-negative values representing rewards earned at each level of a game. For any contiguous segment starting at position l and ending at r, the player’s performance score is computed as the rounded average of that segment: take the sum of values on…

codeforcescompetitive-programming
CF 105383E - Efficient Slabstones Rearrangement

We are given a one-dimensional garden represented as a line of m cells. Several existing slabs are already placed along this line, each occupying a continuous interval.

codeforcescompetitive-programming
CF 105383C - Cards

We are given a collection of cards, each card carrying two numbers: one written on its front side and one on its back side.

codeforcescompetitive-programming
CF 105383A - Animal Farm

We are given a collection of animals, each described by its species name and a numeric influence value. Among these animals, we must form a leadership council by selecting any subset, but the selection is constrained by a single special species called pigs.

codeforcescompetitive-programming
CF 105384I - Increasing Income

We are given a fixed permutation $p$ of size $n$. We are allowed to choose another permutation $q$ of the indices $1$ to $n$.

codeforcescompetitive-programming
CF 105384J - Jesse's Job

We are given a permutation of length $n$. Jesse is allowed to split the positions into two nonempty groups. One group is colored yellow, the other blue.

codeforcescompetitive-programming
CF 105384E - Equalizer Ehrmantraut

We are counting how many pairs of arrays $a$ and $b$, both of length $n$, can be formed using values from $1$ to $m$, such that a specific symmetry condition holds between every pair of positions. Pick any two indices $i < j$.

codeforcescompetitive-programming
CF 105384F - Formal Fring

We are given an integer X, and we consider all multisets made of powers of two such that their sum equals X. Each multiset is just a collection like {1, 1, 2, 8, 8} whose total sum is X. From each such multiset S, we imagine splitting its elements into two groups S1 and S2.

codeforcescompetitive-programming
CF 105384B - Breaking Bad

We are given an $n times n$ grid where each cell contains a value between 0 and 4. We must choose exactly one cell from every row and every column, which means we are effectively selecting a permutation of columns for the rows.

codeforcescompetitive-programming
CF 105384C - Chemistry Class

We are given an even number of students, specifically 2n, each with a numeric chemistry skill. The teacher must split them into n disjoint pairs, so every student belongs to exactly one pair.

codeforcescompetitive-programming
CF 105385L - Intersection of Paths

We are given a weighted tree with up to half a million vertices, and each edge carries a weight that can change temporarily during each query. For every query we first modify exactly one edge weight, and then we are allowed to choose $k$ simple paths in the tree.

codeforcescompetitive-programming
CF 105385M - Palindromic Polygon

We are given a convex polygon with vertices ordered counterclockwise. Each vertex carries a value, and we are allowed to pick any subset of vertices.

codeforcescompetitive-programming
CF 105385J - Colorful Spanning Tree

We are given several test cases. Each test case describes a complete graph, but the graph is not defined on individual vertices directly. Instead, vertices are grouped by colors. For each color i, there are ai identical vertices.

codeforcescompetitive-programming
CF 105385I - Left Shifting

We are given a string and we can rotate it cyclically to the left by some number of positions. A left shift by $d$ means taking the substring starting from position $d$ to the end and attaching the prefix $0 dots d-1$ at the end.

codeforcescompetitive-programming
CF 105385E - Sensors

We are given a line of positions indexed from 0 to n − 1. Initially every position is marked red. Over time, we repeatedly pick one position and permanently flip it to blue. After each flip, we look at a collection of intervals, called sensors.

codeforcescompetitive-programming
CF 105385F - Divide the Sequence

We are given an integer array and we are allowed to split it into exactly $k$ contiguous non-empty segments. Each segment contributes its sum, but the contribution is weighted by the segment’s position from the left.

codeforcescompetitive-programming
CF 105385B - Triangle

We are given several test cases. In each test case, we receive a list of strings. We need to count how many triples of indices $(a, b, c)$ with $a < b < c$ satisfy a special “triangle” condition defined using string concatenation and lexicographic comparison.

codeforcescompetitive-programming
CF 105385A - Printer

We are given several printing machines that run independently but contribute to the same shared goal: producing at least $k$ total copies of a document. Each printer does not work at a constant long-term rate in a simple linear way. Instead, it follows a cycle.

codeforcescompetitive-programming
CF 105386M - Italian Cuisine

We are given a convex polygon representing a pizza, and a circular region inside it representing a pineapple topping.

codeforcescompetitive-programming
CF 105386J - The Quest for El Dorado

We are given a graph of cities connected by undirected roads, where each road belongs to a company and has a length. The structure is fixed, but movement is constrained by a sequence of tickets that must be used in order.

codeforcescompetitive-programming
CF 105386I - Left Shifting 2

We are given a string and we are allowed to cyclically shift it. After choosing a shift, we look at the resulting string arranged in a circle, meaning the last character is considered adjacent to the first.

codeforcescompetitive-programming
CF 105386G - Be Positive

We are asked to build a permutation of numbers from 0 to n minus 1 such that when we read it from left to right, the XOR of every prefix is strictly positive.

codeforcescompetitive-programming
CF 105386F - Collect the Coins

We are given a sequence of events on a number line of integer cells. Each event is a coin that appears at a specific time and position, and it exists for exactly one second.

codeforcescompetitive-programming
CF 105386A - Two-star Contest

We are given several contests. Each contest has a “star rating” and a vector of properties. The score of a contest is simply the sum of all its properties. Some property values are already fixed, while others are missing and marked as unknown.

codeforcescompetitive-programming
CF 105386C - Stop the Castle 2

We are working on a very large grid, but only a sparse set of cells are relevant: some cells contain castles and some contain obstacles. Two castles can “see” each other if they lie in the same row or column and nothing important lies strictly between them.

codeforcescompetitive-programming
CF 105387L - Bee coloring book

We are given a rectangular board with $n$ rows and $m$ columns. Each cell is a hexagon in a honeycomb layout, which means every cell can touch up to six neighbors instead of the usual four in a grid.

codeforcescompetitive-programming
CF 105387K - Stroller

We are given two rectangles. One represents a car trunk with sides a and b, the other represents a folded stroller with sides c and d. The stroller can be rotated by 90 degrees, meaning we can swap its sides, but we cannot deform it.

codeforcescompetitive-programming
CF 105387H - Toys

We are given a deterministic sequence of integers generated by repeatedly multiplying the previous value by a fixed factor and then taking a modulo. The sequence starts from a given initial value and produces exactly $n$ numbers.

codeforcescompetitive-programming
CF 105387F - Questions pack

We are given a database of questions, each question having a computed difficulty score derived from how many teams answered incorrectly relative to attempts. After scaling by 10000 and flooring, each question becomes a single integer rating.

codeforcescompetitive-programming
CF 105387B - Destroy them all!

We are given a very large grid, but only a small number of cells inside it are marked. From this state, we are allowed to choose a single empty cell and pick one of four cardinal directions.

codeforcescompetitive-programming
CF 105387A - Dilation

We are given a binary grid that represents an image after a morphological operation called dilation has been applied. Each cell is either black () or white (.).

codeforcescompetitive-programming
CF 105388J - Non-Interactive Nim

We are given several independent instances of a Nim game. Each instance consists of multiple piles, and a move consists of selecting one pile and removing a positive number of stones from it.

codeforcescompetitive-programming
CF 105388I - Geometry Hacking

We are given a very specific geometric bug to exploit. A point is fixed at the origin, and we are asked to construct simple lattice polygons that truly enclose this point strictly inside them. “Strictly inside” means the origin cannot lie on any edge or vertex.

codeforcescompetitive-programming
CF 105388G - Touching Grass

We are given a set of vertical line segments in the plane, each anchored on the x-axis and extending upward. Concretely, the i-th grass is a segment from $(xi, 0)$ to $(xi, yi)$, and all x-coordinates are distinct.

codeforcescompetitive-programming
CF 105388E - Sum of Squares

We are given a univariate polynomial $A(x)$ and we build a multivariate polynomial $D(x1, dots, xm)$ by taking two ingredients. The first is a copy of $A$ applied independently to each variable, so every variable contributes a factor $A(xi)$.

codeforcescompetitive-programming
CF 105388C - -is-this-bitset-

We are given a rooted binary tree with up to 300,000 nodes. Each node carries a weight a[i], and each node also has a target value b[i]. For every node i, we look only at the nodes on the path from the root to i, including i itself.

codeforcescompetitive-programming
CF 105388A - Coprime Array

We are given two integers, a target sum s and a constraint value x. The task is to construct an array whose elements add up exactly to s, while every element in the array must be coprime with x. Coprime here means that each element shares no common prime factor with x.

codeforcescompetitive-programming
CF 105390D - String From Another World

We are given a target string $s$ and a fixed number of seconds $m$. Starting from an empty string $t$, each second we apply exactly one operation.

codeforcescompetitive-programming
CF 105390B - Simple Update - II

We are given a binary string and a parameter $k$. For each value of $k$ from $1$ up to $lfloor n/2 rfloor$, we are allowed to repeatedly apply a transformation that acts on a window of length $2k$.

codeforcescompetitive-programming
CF 105394L - Laundry

We are given items that must be washed using one of three washing programs, A, B, or C. Each laundry load uses exactly one program and can contain at most $k$ items. Every item does not have a single fixed program, instead it comes with a set of allowed programs.

codeforcescompetitive-programming
CF 105394J - Jigsaw Present

We are given a collection of $n$ jigsaw puzzles. Each puzzle has two attributes: the number of pieces it contains and a difficulty value that can be positive or negative. A “gift” is defined as choosing any subset of these puzzles.

codeforcescompetitive-programming
CF 105394H - Headline Heat

We are given a collection of university names, a set of rivalries between some pairs of universities, and a sequence of news articles. For each article, we must decide whether it is “balanced enough” or whether it would anger at least one coach.

codeforcescompetitive-programming
CF 105394E - Even Odd Game

We are given a finite collection of cards, each card representing a unary operation on a shared integer state. Each move, a player picks an unused card and applies its operation to the current value. The players alternate until all cards are consumed.

codeforcescompetitive-programming
CF 105394D - Dark Alley

We are working on a one-dimensional alley of positions from 1 to n. At certain positions we may place or remove lamps, each lamp having a positive brightness value.

codeforcescompetitive-programming
CF 105394B - Bookshelf Bottleneck

We are given a collection of cuboid-shaped books, and each book can be freely rotated in 3D before being placed. All books must be placed upright on a shelf in a single horizontal row, meaning each book contributes exactly one rectangular footprint on the shelf surface, and…

codeforcescompetitive-programming
CF 105394A - Alien Attack 2

We are given a social network of people where friendships form an undirected graph. The aliens cannot abduct individuals independently.

codeforcescompetitive-programming
CF 105401K - Same Segment

We are given a line of positions from 1 to N, and we must assign each position a value between 0 and K. On top of this array, there are M constraints. Each constraint specifies a segment [l, r] and demands that the sum of values inside that segment is exactly K.

codeforcescompetitive-programming
CF 105401I - Mukjjippa

We are simulating a probabilistic turn-based game where two players repeatedly play rock-paper-scissors, but the outcome does not immediately determine the winner.

codeforcescompetitive-programming
CF 105401G - Make RUN Great Again

We have a set of $N$ clubs whose scores are already fixed, and one additional club called RUN whose score we are free to choose at the end.

codeforcescompetitive-programming
CF 105401C - Counting Regions

We start with an $N times N$ grid where every cell is initially white. The grid is then modified through a fixed sequence of operations, each operation recolors either an entire row or an entire column to black or white.

codeforcescompetitive-programming
CF 105401B - Construct a Coin Set

We are asked to construct a set of coin denominations that interact with the greedy change-making strategy in a very specific way. For any amount, the greedy strategy always picks the largest coin not exceeding the remaining sum.

codeforcescompetitive-programming
CF 105403B - Programming Contest

Each test case gives two arrays of scores, one belonging to Arturo and one belonging to Benito. For every index we have a pair of values, but the pairing is completely unknown: we are free to assign Arturo’s numbers and Benito’s numbers to different contest problems in any…

codeforcescompetitive-programming
CF 105403C - Painting Stones

We are given a line of stones, each stone having either a fixed color already assigned or being unpainted. Our task is to fill in all unpainted stones using a palette of c colors so that no two adjacent stones share the same color.

codeforcescompetitive-programming
CF 105404F - Painting Squares

We start with an empty grid of size $n times m$, where every cell is initially white. The only way to modify the grid is to choose whole rows or whole columns and paint them completely black.

codeforcescompetitive-programming
CF 105404B - Dividing

We are given several independent test cases. Each test case provides a list of positive integers. The task is to determine whether there exists at least one element in the list that can divide every element in the same list, including itself in a trivial way.

codeforcescompetitive-programming
CF 105404C - Games with Queta

We are given a segment on a line, marked by two fixed points. Inside this segment there are several objects, each placed at a distinct coordinate. Every object is initially facing either left toward the first mark or right toward the second mark.

codeforcescompetitive-programming
CF 105408G - GCDland Mystical Arrays

We are given a list of integers and asked to verify a very specific structural property: every pair of numbers in the list must share exactly the same greatest common divisor.

codeforcescompetitive-programming
CF 105416H - Chicken Farm

We are simulating a small economy that evolves over a fixed number of days. Alice starts with a single chicken that already produces eggs every day after it has finished its initial sleep requirement.

codeforcescompetitive-programming
CF 105416F - Incubation Line

We are given a set of positions on a number line where eggs are placed. We are also allowed to place a fixed number of heat lamps, each at an integer coordinate.

codeforcescompetitive-programming
CF 105416B - Hard Boiled

We are given a collection of eggs, where each egg requires a specific amount of time to be fully cooked. Jacob has a fixed total time budget and a single pot, which means he can only cook one egg at a time without overlap.

codeforcescompetitive-programming
CF 105416A - Which is up?

We are given a deterministic process that generates a sequence of egg orientations. Each egg has a state in the range from 0 to 5, and the sequence starts from a fixed initial state for the first egg.

codeforcescompetitive-programming
CF 105417I - Rolling Egg

We are looking at a dynamical system over the finite field $mathbb{F}p$. We pick a starting point $x0$, then repeatedly apply a randomly chosen polynomial function $f : mathbb{F}p to mathbb{F}p$.

codeforcescompetitive-programming
CF 105417H - Chicken Farm

We are given a system that evolves over a limited number of days. Initially there is exactly one chicken and a stock of eggs that starts at zero.

codeforcescompetitive-programming
CF 105417E - Yodel Yolk

We are given a one-dimensional landscape represented as an array of heights. Each index is a position in a mountain range, and the height value is the elevation at that position.

codeforcescompetitive-programming
CF 105417C - Egg Order

We are given a set of integers from 1 to n, each appearing exactly once, and we must arrange them in some order. From this arrangement, we look at contiguous segments and focus on those segments where values increase by exactly 1 at every step.

codeforcescompetitive-programming
CF 105418H - AI Takeover

We start with a population of AI bots arranged in levels. Initially there are only level-n bots, and there are k of them. Time advances in fixed 5-minute steps, and at each step every bot performs exactly one action.

codeforcescompetitive-programming
CF 105418G - Odd Non Primes

We are given several independent test cases. Each test case is a sequence of integers representing a row of cards.

codeforcescompetitive-programming
CF 105418F - Oddly Even Challenge

We are asked to count how many integers in the range from 0 up to a given large number satisfy a positional digit rule. The rule depends on writing each number in decimal and looking at its digits from left to right using 1-based indexing.

codeforcescompetitive-programming
CF 105418E - Magical Coins

We are given a set of coin denominations that follow a very structured pattern: each coin is a number consisting entirely of digit 1, and the lengths grow in a special way. So we get values like 11, 111, 1111, 11111, and so on, continuing indefinitely.

codeforcescompetitive-programming
CF 105418D - Harsh and profits

The problem describes a profit process that grows in a very structured way. On the first day Harsh earns nothing, and each next day his daily gain increases by exactly one more unit than the previous increase.

codeforcescompetitive-programming
CF 105418A - Phoenix Against the Monsters

We are given a directed network of cities connected by roads, where each road has a non-negative cost representing how many monsters Phoenix must fight if he travels along it. Phoenix starts at city 1 and must reach city n using any sequence of directed roads.

codeforcescompetitive-programming
CF 105418B - Spidey and the Palindrome Sequence

We are given a string and we are allowed to rearrange its characters arbitrarily. After rearrangement, we want to split the resulting string into several consecutive blocks. Every block must be a palindrome and all blocks must have the same length.

codeforcescompetitive-programming
CF 105423E - 拼接串

We are given a long sequence of integers, each value lying between 1 and 18. From this sequence we are allowed to pick two contiguous subarrays, and then concatenate them in order to form a new sequence.

codeforcescompetitive-programming
CF 105423K - 渡劫

We are given a connected undirected graph with $n$ islands and $m$ tunnels. Each island has a cost $ai$, representing the energy needed to perform a ritual if you are currently on that island. Each tunnel connects two islands and has a travel cost.

codeforcescompetitive-programming
CF 105423J - Beautiful Sequence

We are given two permutations of the numbers from 1 to n. The task is to count how many sequences are simultaneously subsequences of both permutations, under a very specific structural constraint.

codeforcescompetitive-programming
CF 105423I - 数据检索系统

We are building a simplified membership system that behaves like a hash-filtered set with multiple hash functions. The system stores elements in a binary array of size n, initially all zeros.

codeforcescompetitive-programming
CF 105423H - 经文

We are given a target pattern string $s$ and we want to build strings of length $n$ using lowercase English letters. Inside each constructed string, we look for occurrences of $s$ as contiguous substrings.

codeforcescompetitive-programming
CF 105423G - Utakotoba

We are given a line of n positions, each holding a 15-bit non-negative integer. We are allowed to perform an operation on any adjacent pair of positions.

codeforcescompetitive-programming
CF 105423F - 阅读理解

We are given a tree that comes from a transformation process applied to some directed graph. The process runs a depth-first search, assigns discovery times, maintains a stack of vertices, and whenever a specific low-link condition is met it creates a new auxiliary node and…

codeforcescompetitive-programming
CF 105423D - Too much noise!

We are given a collection of signals. Each signal has two numeric attributes: an energy value and a frequency value. The task is to consider every ordered pair of signals and accumulate a cost defined by a product of two independent parts.

codeforcescompetitive-programming
CF 105423B - HolyK's Land

We are given a tree of cities. Each query activates a consecutive block of “movie options”, and each option corresponds to selecting all cities along the unique tree path between two given endpoints.

codeforcescompetitive-programming
CF 105423A - 贪吃蛇

We are given a set of points on a 2D plane, each representing a coin. A snake starts at the origin and can only move in two directions: right and up, meaning in whatever coordinate system we choose, its x coordinate and y coordinate never decrease along its path.

codeforcescompetitive-programming
CF 105423C - easy math

We are given a small list of numbers, each of which is a power of two. That means every element can be written as $2^{ki}$ where the exponent $ki$ is a small non-negative integer.

codeforcescompetitive-programming
CF 105424K - Apocalypse

We are given a convex polygon that represents an initial infected region on an infinite plane. Over time, the infection expands outward in a very structured but not explicitly geometric way: the only guarantee is that the “shape family” preserves radial ordering from the…

codeforcescompetitive-programming
CF 105424I - Snakes\&Snakes

We are given a one-dimensional board of size $N$, where a token starts at cell 1 and wants to reach cell $N$. Between these endpoints, some cells contain “snakes” that push the token left by a fixed amount whenever it lands there.

codeforcescompetitive-programming
CF 105424J - Binary Trees

We are given two rooted binary trees on the same set of vertices labeled from 0 to N−1. The first tree is the initial configuration, and the second tree is the target configuration.

codeforcescompetitive-programming
CF 105424D - Klyukalo

We are given a construction made of $N$ independent parts. Each part has a required standard weight $si$, and the current configuration has weight $ai$.

codeforcescompetitive-programming
CF 105427K - Karl Coder

We are given an array-like buffer of length $2N$, but $N$ is unknown. The structure of this buffer is very specific: the first $N$ positions store nonzero bytes, while the remaining $N$ positions store zeros.

codeforcescompetitive-programming
CF 105427J - Jamboree

We are given a collection of items, each with a positive size, and a fixed number of scouts. Each item must be assigned to exactly one scout. A scout can carry at most two items, and the load of a scout is the sum of the sizes of items assigned to them.

codeforcescompetitive-programming
CF 105427I - Intertwined

A rope is initially stretched from the origin to a fixed point on the positive x-axis. We then start rotating this rope counter-clockwise around whichever point is currently acting as its pivot. At the beginning, the pivot is the origin.

codeforcescompetitive-programming
CF 105427G - Groups of Strangers

We are given a social graph of employees where edges represent mutual acquaintance. The task is to split all employees into three groups such that no two people who know each other end up in the same group.

codeforcescompetitive-programming